Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 15 Aug 2010 14:50:03 +0000 (UTC)
From:      Dag-Erling Smorgrav <des@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r211337 - head/lib/libutil
Message-ID:  <201008151450.o7FEo3cZ063365@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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':



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201008151450.o7FEo3cZ063365>