Skip to content

Commit

Permalink
hsearch: fix potential UB (pointer arithmetics on nullptr)
Browse files Browse the repository at this point in the history
closes #471
addresses #470
  • Loading branch information
rofl0r committed Feb 1, 2023
1 parent 3764b85 commit 6ffd9af
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/hsearch.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ static int resize(struct htab *htab, size_t nel)
{
size_t newsize;
size_t i, j;
size_t oldmask = htab->mask;
struct elem *e, *newe;
struct elem *oldtab = htab->elems;
struct elem *oldend = htab->elems + htab->mask + 1;
struct elem *oldend;

if (nel > MAXSIZE)
nel = MAXSIZE;
Expand All @@ -95,6 +96,8 @@ static int resize(struct htab *htab, size_t nel)
htab->mask = newsize - 1;
if (!oldtab)
return 1;

oldend = oldtab + oldmask + 1;
for (e = oldtab; e < oldend; e++)
if (e->item.key) {
for (i=e->hash,j=1; ; i+=j++) {
Expand Down

0 comments on commit 6ffd9af

Please sign in to comment.