From: Paul Eggert Date: Wed, 3 May 2006 01:08:27 +0000 (+0000) Subject: * doc/autoconf.texi (Integer Overflow): X-Git-Tag: AUTOCONF-2.59d~90 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=28fb17bb7618db6be8bbfea1fe13f7ae25c5cc17;p=thirdparty%2Fautoconf.git * doc/autoconf.texi (Integer Overflow): Mention the special case of integer division overflow. --- diff --git a/ChangeLog b/ChangeLog index 051ac1ccf..78716f6ec 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,12 +1,15 @@ 2006-05-02 Paul Eggert * doc/autoconf.texi: Use @option systematically. + (Integer Overflow): 2006-05-02 Paul Eggert and Bruno Haible * doc/autoconf.texi (Limitations of Usual Tools): Add a paragraph about 'od'. + (Integer Overflow): Mention the special case of integer division + overflow. 2006-05-02 Ralf Wildenhues diff --git a/doc/autoconf.texi b/doc/autoconf.texi index 5795813b9..4996f05c5 100644 --- a/doc/autoconf.texi +++ b/doc/autoconf.texi @@ -14267,17 +14267,23 @@ the programs work well enough in practice. @cindex overflow, arithmetic In C, signed integer overflow leads to undefined behavior. However, -many programs and Autoconf tests assume that integer overflow silently -wraps around modulo a power of 2 so long as you cast the resulting value +many programs and Autoconf tests assume that signed integer overflow after +addition, subtraction, or multiplication silently +wraps around modulo a power of two, using two's complement arithmetic, +so long as you cast the resulting value to an integer type or store it into an integer variable. Such programs -are portable to the vast majority of modern platforms. C99 has a way of -specifying this portability (the LIA-1 option) but this is not -universally supported yet. GCC users might consider using the +are portable to the vast majority of modern platforms. However, signed +integer division is not always harmless: for example, on CPUs of the +i386 family, dividing @code{INT_MIN} by @code{-1} yields a SIGFPE signal +which by default terminates the program. + +GCC users might consider using the @option{-ftrapv} option if they are worried about porting their code to -the rare platforms where overflow does not wrap around. +the rare platforms where signed integer overflow does not wrap around +after addition, subtraction, or multiplication. -In contrast, unsigned integer overflow reliably wraps around modulo the -word size. +Unsigned integer overflow reliably wraps around modulo the word size. +This is guaranteed by the C standard and is portable in practice. @node Null Pointers @section Properties of Null Pointers