hsearch: fix potential UB (pointer arithmetics on nullptr)
closes #471 addresses #470
This commit is contained in:
parent
3764b85514
commit
6ffd9af2c7
@ -80,9 +80,10 @@ static int resize(struct htab *htab, size_t nel)
|
|||||||
{
|
{
|
||||||
size_t newsize;
|
size_t newsize;
|
||||||
size_t i, j;
|
size_t i, j;
|
||||||
|
size_t oldmask = htab->mask;
|
||||||
struct elem *e, *newe;
|
struct elem *e, *newe;
|
||||||
struct elem *oldtab = htab->elems;
|
struct elem *oldtab = htab->elems;
|
||||||
struct elem *oldend = htab->elems + htab->mask + 1;
|
struct elem *oldend;
|
||||||
|
|
||||||
if (nel > MAXSIZE)
|
if (nel > MAXSIZE)
|
||||||
nel = MAXSIZE;
|
nel = MAXSIZE;
|
||||||
@ -95,6 +96,8 @@ static int resize(struct htab *htab, size_t nel)
|
|||||||
htab->mask = newsize - 1;
|
htab->mask = newsize - 1;
|
||||||
if (!oldtab)
|
if (!oldtab)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
oldend = oldtab + oldmask + 1;
|
||||||
for (e = oldtab; e < oldend; e++)
|
for (e = oldtab; e < oldend; e++)
|
||||||
if (e->item.key) {
|
if (e->item.key) {
|
||||||
for (i=e->hash,j=1; ; i+=j++) {
|
for (i=e->hash,j=1; ; i+=j++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user