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.
This commit is contained in:
Paul Eggert
2024-08-02 22:13:20 -07:00
parent 281e03ec6c
commit 414f635d8b
2 changed files with 5 additions and 8 deletions

View File

@@ -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

View File

@@ -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++;
}
}