svn commit: r211337 - head/lib/libutil

Dag-Erling Smorgrav des at FreeBSD.org
Sun Aug 15 14:50:03 UTC 2010


Author: des
Date: Sun Aug 15 14:50:03 2010
New Revision: 211337
URL: http://svn.freebsd.org/changeset/base/211337

Log:
  Fix the overflow test.  It is possible for the result of an
  overflowing shift to be larger than the original value, e.g.
  
           (uint64_t)1 << 53 = 0x20000000000000
   ((uint64_t)1 << 53) << 10 = 0x8000000000000000

Modified:
  head/lib/libutil/expand_number.c

Modified: head/lib/libutil/expand_number.c
==============================================================================
--- head/lib/libutil/expand_number.c	Sun Aug 15 14:44:48 2010	(r211336)
+++ head/lib/libutil/expand_number.c	Sun Aug 15 14:50:03 2010	(r211337)
@@ -67,7 +67,7 @@ expand_number(const char *buf, uint64_t 
 	}
 
 #define SHIFT(n, b)							\
-	do { if ((n << b) < n) goto overflow; n <<= b; } while (0)
+	do { if (((n << b) >> b) != n) goto overflow; n <<= b; } while (0)
 
 	switch (tolower((unsigned char)*endptr)) {
 	case 'e':


More information about the svn-src-all mailing list