Skip to content

Commit

Permalink
elasticarray: remove redundant checks
Browse files Browse the repository at this point in the history
  • Loading branch information
dorjoy03 committed Oct 15, 2023
1 parent 4773012 commit 756f05c
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions libcperciva/datastruct/elasticarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ elasticarray_append(struct elasticarray * EA,
size_t nsize;

/* Check for overflow. */
if ((nrec > SIZE_MAX / reclen) ||
(nrec * reclen > SIZE_MAX - EA->size)) {
if (nrec > ((SIZE_MAX - EA->size) / reclen)) {
errno = ENOMEM;
goto err0;
}
Expand Down Expand Up @@ -205,8 +204,7 @@ elasticarray_shrink(struct elasticarray * EA, size_t nrec, size_t reclen)
size_t nsize;

/* Figure out how much to keep. */
if ((nrec > SIZE_MAX / reclen) ||
(nrec * reclen > EA->size))
if (nrec > EA->size / reclen)
nsize = 0;
else
nsize = EA->size - nrec * reclen;
Expand Down

0 comments on commit 756f05c

Please sign in to comment.