prevent hash set/map insertion of deleted entries

Just like the recently-added checks for empty entries, add checks for
deleted entries as well.  This didn't catch any problems, but it might
prevent future accidents.  Suggested by David Malcolm.


for  gcc/ChangeLog

	* hash-map.h (put, get_or_insert): Check that added entry
	doesn't look deleted either.
	* hash-set.h (add): Likewise.
This commit is contained in:
Alexandre Oliva 2022-12-29 14:33:07 -03:00 committed by Alexandre Oliva
parent 512af6c380
commit 603da20168
2 changed files with 7 additions and 4 deletions

View file

@ -173,8 +173,9 @@ public:
if (ins)
{
e->m_key = k;
new ((void *) &e->m_value) Value (v);
gcc_checking_assert (!Traits::is_empty (*e));
new ((void *)&e->m_value) Value (v);
gcc_checking_assert (!Traits::is_empty (*e)
&& !Traits::is_deleted (*e));
}
else
e->m_value = v;
@ -204,7 +205,8 @@ public:
{
e->m_key = k;
new ((void *)&e->m_value) Value ();
gcc_checking_assert (!Traits::is_empty (*e));
gcc_checking_assert (!Traits::is_empty (*e)
&& !Traits::is_deleted (*e));
}
if (existed != NULL)

View file

@ -61,7 +61,8 @@ public:
{
new (e) Key (k);
// Catch attempts to insert e.g. a NULL pointer.
gcc_checking_assert (!Traits::is_empty (*e));
gcc_checking_assert (!Traits::is_empty (*e)
&& !Traits::is_deleted (*e));
}
return existed;