Source-Changes-HG archive

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

[src/trunk]: src/external/bsd/bind/dist/lib/isc/unix/include/isc Replace arit...



details:   https://anonhg.NetBSD.org/src/rev/fa8c73fede1b
branches:  trunk
changeset: 340550:fa8c73fede1b
user:      joerg <joerg%NetBSD.org@localhost>
date:      Sat Sep 12 19:03:11 2015 +0000

description:
Replace arithmetic using undefined behavior with exhaustive list of type
size limits.

diffstat:

 external/bsd/bind/dist/lib/isc/unix/include/isc/offset.h |  19 +++++----------
 1 files changed, 7 insertions(+), 12 deletions(-)

diffs (33 lines):

diff -r 0d78a9abc90a -r fa8c73fede1b external/bsd/bind/dist/lib/isc/unix/include/isc/offset.h
--- a/external/bsd/bind/dist/lib/isc/unix/include/isc/offset.h  Sat Sep 12 18:30:46 2015 +0000
+++ b/external/bsd/bind/dist/lib/isc/unix/include/isc/offset.h  Sat Sep 12 19:03:11 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: offset.h,v 1.4 2014/12/10 04:38:01 christos Exp $      */
+/*     $NetBSD: offset.h,v 1.5 2015/09/12 19:03:11 joerg Exp $ */
 
 /*
  * Copyright (C) 2004, 2005, 2007, 2008  Internet Systems Consortium, Inc. ("ISC")
@@ -32,17 +32,12 @@
 
 typedef off_t isc_offset_t;
 
-/*%
- * POSIX says "Additionally, blkcnt_t and off_t are extended signed integral
- * types", so the maximum value is all 1s except for the high bit.
- * This definition is more complex than it really needs to be because it was
- * crafted to keep both the SunOS 5.6 and the HP/UX 11 compilers quiet about
- * integer overflow.  For example, though this is equivalent to just left
- * shifting 1 to the high bit and then inverting the bits, the SunOS compiler
- * is unhappy about shifting a positive "1" to negative in a signed integer.
- */
 #define ISC_OFFSET_MAXIMUM \
-       (~(((off_t)-1 >> (sizeof(off_t) * CHAR_BIT - 1)) \
-                     << (sizeof(off_t) * CHAR_BIT - 1)))
+    (sizeof(off_t) == sizeof(char) ? INT_MAX : \
+     (sizeof(off_t) == sizeof(short) ? SHRT_MAX : \
+      (sizeof(off_t) == sizeof(int) ? INT_MAX : \
+       (sizeof(off_t) == sizeof(long) ? LONG_MAX : \
+        (sizeof(off_t) == sizeof(long long) ? LLONG_MAX : INTMAX_MAX)))))
+
 
 #endif /* ISC_OFFSET_H */



Home | Main Index | Thread Index | Old Index