bug-autoconf
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

integer overflow documentation


From: Bruno Haible
Subject: integer overflow documentation
Date: Tue, 2 May 2006 16:48:53 +0200
User-agent: KMail/1.5

Hi Paul,

Here's a patch to correct the slightly wrong statement that "integer overflow
silently wraps around ... the vast majority of modern platforms".

The special case of signed division overflow is rarely relevant in practice,
but it's instructive to know that even on modern platforms, integer arithmetic
can lead to a fatal signal.


2006-05-01  Bruno Haible  <address@hidden>

        * doc/autoconf.texi (Integer Overflow): Mention the special case of
        integer division overflow.

--- autoconf.texi.bak   2006-05-01 22:15:21.000000000 +0200
+++ autoconf.texi       2006-05-01 23:09:41.000000000 +0200
@@ -14217,14 +14217,18 @@
 @cindex overflow, arithmetic
 
 In C, signed integer overflow leads to undefined behavior.  However,
-many programs and Autoconf tests assume that integer overflow silently
+many programs and Autoconf tests assume that integer overflow in all
+arithmetic operations except division silently
 wraps around modulo a power of 2 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
address@hidden option if they are worried about porting their code to
-the rare platforms where overflow does not wrap around.
+universally supported yet.  Integer overflow during signed integer division,
+on the other hand, is not harmless: On CPUs of the i386 family, division
address@hidden / -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.
 
 In contrast, unsigned integer overflow reliably wraps around modulo the
 word size.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]