Re: [Debian-med-packaging] Bug#853568: No idea how to fix abs arguments in nanopolish (original) (raw)
- To: Walter Landry <wlandry@caltech.edu>, 853568@bugs.debian.org, andreas@an3as.eu
- Cc: debian-mentors@lists.debian.org
- Subject: Re: [Debian-med-packaging] Bug#853568: No idea how to fix abs arguments in nanopolish
- From: Gert Wollny <gw.fossdev@gmail.com>
- Date: Fri, 01 Sep 2017 09:47:29 +0200
- Message-id: <[🔎] 1504252049.7063.5.camel@gmail.com>
- In-reply-to: <[🔎] 20170831.210035.377614749309283436.wlandry@caltech.edu>
- References: 20170831215429.hye2igcefyyiyjix@an3as.eu E1cYUpL-0007U6-QZ@paradis.debian.org <[🔎] 20170831.210035.377614749309283436.wlandry@caltech.edu>
Am Donnerstag, den 31.08.2017, 21:00 -0700 schrieb Walter Landry:
Andreas Tille andreas@an3as.eu wrote:
Hi,
to fix bug #853568 I tried a patch (gcc-7.patch) to fix abs() arguments in nanopolish[1] but I have no idea how to deal with this:
... g++ -o src/hmm/nanopolish_pore_model_set.o -c -g -O2 -fdebug- prefix-map=/build/nanopolish-0.5.0=. -fstack-protector-strong -Wformat -Werror=format-security -g -O3 -std=c++11 -fopenmp -Wdate- t src/common/nanopolish_variant.cpp: In function 'std::vector extract_variants(const string&, const string&)': src/common/nanopolish_variant.cpp:32:69: error: call of overloaded 'abs(std::__cxx11::basic_string::size_type)' is ambiguous      size_t difference = std::abs(reference.size() - haplotype.size());
The result of subtracting two size_t's is still a size_t, which is unsigned.  So you need to cast it to a signed type.  The correct type is ptrdiff_t.
 http://en.cppreference.com/w/cpp/types/ptrdiff_t
The line then becomes
 size_t difference = std::abs(static_cast(reference.size() - haplotype.size()));
Casting the difference may result in undefined behavior. Consider the case
reference.size() == 1 haplotype.size() == 2
thenÂ
reference.size() - haplotype.size()Â
will be 0xFFFFFFFF (on 32 bit), and how this is casted to a signed type is implementation dependent (i.e. it is not guaranteed that this simply wraps to -1, it may also raise a trap because of integer overflow).
It would be better to avoid the cast altogether by doing something like
 size_t difference = reference.size() > haplotype.size() ? reference.size() - haplotype.size() : haplotype.size() - reference.size();
or cast both values before doing the subtraction.
Best, Gert
Reply to:
- References:
- Re: No idea how to fix abs arguments in nanopolish
* From: Walter Landry wlandry@caltech.edu
- Re: No idea how to fix abs arguments in nanopolish
- Prev by Date:Re: No idea how to fix abs arguments in nanopolish
- Next by Date:Bug#873938: RFS: engauge-digitizer/10.3+ds.1-1
- Previous by thread:Re: No idea how to fix abs arguments in nanopolish
- Next by thread:Bug#873938: RFS: engauge-digitizer/10.3+ds.1-1
- Index(es):