Skip to content

Commit 1ce7059

Browse files
Make signed overflow behave "correctly"
Fix for issue arduino#4511 In short, the documentation says that signed integer overflow causes the value to "roll over". Actually, this results in undefined behavior, with potentially unpredictable results. This patch adds a GCC option to treat signed integers the "right" way so that they roll over as the documentation claims.
1 parent 06e9981 commit 1ce7059

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

hardware/arduino/avr/platform.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ compiler.warning_flags.all=-Wall -Wextra
2020
# Default "compiler.path" is correct, change only if you want to overidde the initial value
2121
compiler.path={runtime.tools.avr-gcc.path}/bin/
2222
compiler.c.cmd=avr-gcc
23-
compiler.c.flags=-c -g -Os {compiler.warning_flags} -std=gnu11 -ffunction-sections -fdata-sections -MMD
23+
compiler.c.flags=-c -g -Os {compiler.warning_flags} -std=gnu11 -fwrapv -ffunction-sections -fdata-sections -MMD
2424
# -w flag added to avoid printing a wrong warning http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59396
2525
# This is fixed in gcc 4.8.3 and will be removed as soon as we update the toolchain
2626
compiler.c.elf.flags={compiler.warning_flags} -Os -Wl,--gc-sections
2727
compiler.c.elf.cmd=avr-gcc
2828
compiler.S.flags=-c -g -x assembler-with-cpp
2929
compiler.cpp.cmd=avr-g++
30-
compiler.cpp.flags=-c -g -Os {compiler.warning_flags} -std=gnu++11 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD
30+
compiler.cpp.flags=-c -g -Os {compiler.warning_flags} -std=gnu++11 -fwrapv -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD
3131
compiler.ar.cmd=avr-ar
3232
compiler.ar.flags=rcs
3333
compiler.objcopy.cmd=avr-objcopy

0 commit comments

Comments
 (0)