From: Paul Eggert Date: Sat, 3 Aug 2024 05:13:20 +0000 (-0700) Subject: Use ckd_mul, ckd_add in from_header X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=414f635d8bba4c8894855040b1e6b77b07dc07bd;p=thirdparty%2Ftar.git Use ckd_mul, ckd_add in from_header * src/common.h (LG_64): Remove; no longer used. * src/list.c (from_header): Use ckd_mul, ckd_add rather than doing it by hand. --- diff --git a/src/common.h b/src/common.h index 0120bf46..8a22c2ba 100644 --- a/src/common.h +++ b/src/common.h @@ -64,7 +64,6 @@ /* Log base 2 of common values. */ #define LG_8 3 -#define LG_64 6 #define LG_256 8 _GL_INLINE_HEADER_BEGIN diff --git a/src/list.c b/src/list.c index 339a650b..6133b0c7 100644 --- a/src/list.c +++ b/src/list.c @@ -793,7 +793,7 @@ from_header (char const *where0, size_t digs, char const *type, /* Compute the negative of the input value, assuming two's complement. */ int digit = (*where1 - '0') | 4; - overflow = 0; + overflow = false; value = 0; where = where1; for (;;) @@ -803,11 +803,9 @@ from_header (char const *where0, size_t digs, char const *type, if (where == lim || ! is_octal_digit (*where)) break; digit = *where - '0'; - overflow |= value != (value << LG_8 >> LG_8); - value <<= LG_8; + overflow |= ckd_mul (&value, value, 8); } - value++; - overflow |= !value; + overflow |= ckd_add (&value, value, 1); if (!overflow && value <= minus_minval) { @@ -853,7 +851,7 @@ from_header (char const *where0, size_t digs, char const *type, while (where != lim && (dig = base64_map[(unsigned char) *where]) < 64) { - if (value << LG_64 >> LG_64 != value) + if (ckd_mul (&value, value, 64)) { if (type && !silent) ERROR ((0, 0, @@ -861,7 +859,7 @@ from_header (char const *where0, size_t digs, char const *type, quote_mem (where0, digs), type)); return -1; } - value = (value << LG_64) | dig; + value |= dig; where++; } }