maint: prefer ckd_add for overflow checks

* src/cksum.c (cksum_slice8, crc32b_sum_stream): Use ckd_add to check
for overflow.
* src/cksum_avx2.c (cksum_avx2): Likewise.
* src/cksum_avx512.c (cksum_avx512): Likewise.
* src/cksum_pclmul.c (cksum_pclmul): Likewise.
* src/cksum_vmull.c (cksum_vmull): Likewise.
This commit is contained in:
Collin Funk 2025-10-26 12:20:01 -07:00
parent 8ba47d09a3
commit ffa2632dcd
5 changed files with 6 additions and 12 deletions

View File

@ -239,12 +239,11 @@ cksum_slice8 (FILE *fp, uint_fast32_t *crc_out, uintmax_t *length_out)
{
uint32_t *datap;
if (length + bytes_read < length)
if (ckd_add (&length, length, bytes_read))
{
errno = EOVERFLOW;
return false;
}
length += bytes_read;
/* Process multiples of 8 bytes */
datap = (uint32_t *)buf;
@ -335,12 +334,11 @@ crc32b_sum_stream (FILE *stream, void *resstream, uintmax_t *reslen)
while ((bytes_read = fread (buf, 1, BUFLEN, stream)) > 0)
{
if (len + bytes_read < len)
if (ckd_add (&len, len, bytes_read))
{
errno = EOVERFLOW;
return -1;
}
len += bytes_read;
crc = crc32_update (crc, (char const *)buf, bytes_read);

View File

@ -68,12 +68,11 @@ cksum_avx2 (FILE *fp, uint_fast32_t *crc_out, uintmax_t *length_out)
__m256i *datap;
if (length + bytes_read < length)
if (ckd_add (&length, length, bytes_read))
{
errno = EOVERFLOW;
return false;
}
length += bytes_read;
datap = (__m256i *)buf;

View File

@ -75,12 +75,11 @@ cksum_avx512 (FILE *fp, uint_fast32_t *crc_out, uintmax_t *length_out)
__m512i *datap;
if (length + bytes_read < length)
if (ckd_add (&length, length, bytes_read))
{
errno = EOVERFLOW;
return false;
}
length += bytes_read;
datap = (__m512i *)buf;

View File

@ -66,12 +66,11 @@ cksum_pclmul (FILE *fp, uint_fast32_t *crc_out, uintmax_t *length_out)
__m128i fold_data;
__m128i xor_crc;
if (length + bytes_read < length)
if (ckd_add (&length, length, bytes_read))
{
errno = EOVERFLOW;
return false;
}
length += bytes_read;
datap = (__m128i *)buf;

View File

@ -72,12 +72,11 @@ cksum_vmull (FILE *fp, uint_fast32_t *crc_out, uintmax_t *length_out)
uint64x2_t fold_data;
uint64x2_t xor_crc;
if (length + bytes_read < length)
if (ckd_add (&length, length, bytes_read))
{
errno = EOVERFLOW;
return false;
}
length += bytes_read;
datap = (uint64x2_t *) buf;