[map] Protect more against pointer deref

This commit is contained in:
Behdad Esfahbod 2019-04-02 20:17:27 -07:00
parent 5bffa9e375
commit 31c1a83899
1 changed files with 3 additions and 2 deletions

View File

@ -63,6 +63,7 @@ struct hb_hashmap_t
bool operator == (const item_t &o) { return *this == o.key; }
bool is_unused () const { return key == kINVALID; }
bool is_tombstone () const { return key != kINVALID && value == vINVALID; }
bool is_real () const { return key != kINVALID && value != vINVALID; }
};
hb_object_header_t header;
@ -136,7 +137,7 @@ struct hb_hashmap_t
/* Insert back old items. */
if (old_items)
for (unsigned int i = 0; i < old_size; i++)
if (old_items[i].key != kINVALID && old_items[i].value != vINVALID)
if (old_items[i].is_real ())
set (old_items[i].key, old_items[i].value);
free (old_items);
@ -173,7 +174,7 @@ struct hb_hashmap_t
{
if (unlikely (!items)) return vINVALID;
unsigned int i = bucket_for (key);
return !items[i].is_unused () && items[i] == key ? items[i].value : vINVALID;
return items[i].is_real () && items[i] == key ? items[i].value : vINVALID;
}
void del (K key) { set (key, vINVALID); }