dovecot-2.2: lib: strnum - simplify hex and oct overflow code

dovecot at dovecot.org dovecot at dovecot.org
Thu Sep 3 11:03:08 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/29e0a3ea7497
changeset: 19076:29e0a3ea7497
user:      Phil Carmody <phil at dovecot.fi>
date:      Thu Sep 03 14:01:57 2015 +0300
description:
lib: strnum - simplify hex and oct overflow code
uintmax_t is defined to have modulo-2^n semantics, and therefore the bottom
bits of (uintmax_t) are guaranteed to be all set. Therefore the checking of
the next character read is unnecessary, as it's already done in the loop
control statement itself. (This is not true about the bottom digit base 10,
which is why the check remains in the decimal case)

Signed-off-by: Phil Carmody <phil at dovecot.fi>

diffstat:

 src/lib/strnum.c |  16 ++++------------
 1 files changed, 4 insertions(+), 12 deletions(-)

diffs (33 lines):

diff -r f313cda93533 -r 29e0a3ea7497 src/lib/strnum.c
--- a/src/lib/strnum.c	Mon Aug 31 22:31:19 2015 +0000
+++ b/src/lib/strnum.c	Thu Sep 03 14:01:57 2015 +0300
@@ -160,12 +160,8 @@
 		return -1;
 
 	do {
-		if (n >= ((uintmax_t)-1 >> 4)) {
-			if (n > (uintmax_t)-1 >> 4)
-				return -1;
-			if ((uintmax_t)hex > ((uintmax_t)-1 & 0x0f))
-				return -1;
-		}
+		if (n > (uintmax_t)-1 >> 4)
+			return -1;
 		n = (n << 4) + hex;
 		str++;
 	} while (_str_parse_hex(*str, &hex) >= 0);
@@ -230,12 +226,8 @@
 		return -1;
 
 	for (; *str >= '0' && *str <= '7'; str++) {
-		if (n >= ((uintmax_t)-1 >> 3)) {
-			if (n > (uintmax_t)-1 >> 3)
-				return -1;
-			if ((uintmax_t)(*str - '0') > ((uintmax_t)-1 & 0x03))
-				return -1;
-		}
+		if (n > (uintmax_t)-1 >> 3)
+			return -1;
 		n = (n << 3) + (*str - '0');
 	}
 	if (endp_r != NULL)


More information about the dovecot-cvs mailing list