mirror of
https://https.git.savannah.gnu.org/git/coreutils.git
synced 2026-01-27 01:44:21 +00:00
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:
parent
8ba47d09a3
commit
ffa2632dcd
@ -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);
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user