intprops: remove assumption about A|B representation
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 20 May 2011 18:30:16 +0000 (11:30 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 20 May 2011 18:30:16 +0000 (11:30 -0700)
* lib/intprops.h (_GL_BINARY_OP_OVERFLOW): Do not assume that A|B
is a valid integer if both A and B are.  Although this is true for
all known practical hosts, the C standard doesn't guarantee it,
and the code need not assume it.  Also, this change may work around
HP-UX 11.23 and IRIX 6.5 cc bugs reported by Bruno Haible in
<http://lists.gnu.org/archive/html/bug-gnulib/2011-05/msg00426.html>.

ChangeLog
lib/intprops.h

index e1f9b6773dc0c4e94cc9ed05053e91e404269f0c..1f7eef809b132845a7dc963082fa5724b6ba1780 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2011-05-20  Paul Eggert  <eggert@cs.ucla.edu>
+
+       intprops: remove assumption about A|B representation
+       * lib/intprops.h (_GL_BINARY_OP_OVERFLOW): Do not assume that A|B
+       is a valid integer if both A and B are.  Although this is true for
+       all known practical hosts, the C standard doesn't guarantee it,
+       and the code need not assume it.  Also, this change may work around
+       HP-UX 11.23 and IRIX 6.5 cc bugs reported by Bruno Haible in
+       <http://lists.gnu.org/archive/html/bug-gnulib/2011-05/msg00426.html>.
+
 2011-05-20  Eric Blake  <eblake@redhat.com>
 
        perror: work around FreeBSD bug
index bd9f04042e03253eb8d7bab1e10d5062ffb1ce3c..293204ab43a12cf92f510ed84a336324af83d824 100644 (file)
 /* Return 1 if the expression A <op> B would overflow,
    where OP_RESULT_OVERFLOW (A, B, MIN, MAX) does the actual test,
    assuming MIN and MAX are the minimum and maximum for the result type.
-
-   This macro assumes that A | B is a valid integer if both A and B are,
-   which is true of all known practical hosts.  If this is a problem
-   for you, please let us know how to fix it for your host.  */
+   Arguments should be free of side effects.  */
 #define _GL_BINARY_OP_OVERFLOW(a, b, op_result_overflow)        \
   op_result_overflow (a, b,                                     \
-                      _GL_INT_MINIMUM ((a) | (b)),              \
-                      _GL_INT_MAXIMUM ((a) | (b)))
+                      _GL_INT_MINIMUM ((b) - (b) + (a)),        \
+                      _GL_INT_MAXIMUM ((b) - (b) + (a)))
 
 #endif /* _GL_INTPROPS_H */