This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug sanitizer/88479] sanitizer should provide an option to detect conversion to signed integer that overflows
- From: "vincent-gcc at vinc17 dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 14 Dec 2018 00:00:09 +0000
- Subject: [Bug sanitizer/88479] sanitizer should provide an option to detect conversion to signed integer that overflows
- Auto-submitted: auto-generated
- References: <bug-88479-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88479
--- Comment #5 from Vincent Lefèvre <vincent-gcc at vinc17 dot net> ---
(In reply to joseph@codesourcery.com from comment #4)
> If you want to do modulo arithmetic on signed values, the idiom (in
> common-usage C which supports conversions to signed integer types as being
> modulo) is to convert to unsigned, do arithmetic on unsigned and convert
> back to signed.
The conversion back to signed can be done without involving the
implementation-defined behavior, e.g. with a macro that consider the two cases.
This is much better as the conversion is explicit.