diff mbox series

[12/13] hash set: reject attempts to add empty values

Message ID ormt79ea05.fsf@lxoliva.fsfla.org
State New
Headers show
Series [01/13] scoped tables: insert before further lookups | expand

Commit Message

Alexandre Oliva Dec. 27, 2022, 4:38 a.m. UTC
Check, after adding a key to a hash set, that the entry does not look
empty.

Regstrapped on x86_64-linux-gnu.  Ok to install?


for  gcc/ChangeLog

	* hash-set.h (add): Check that the inserted entry does not
	look empty.
---
 gcc/hash-set.h |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Jeff Law Dec. 27, 2022, 3:30 p.m. UTC | #1
On 12/26/22 21:38, Alexandre Oliva via Gcc-patches wrote:
> 
> Check, after adding a key to a hash set, that the entry does not look
> empty.
> 
> Regstrapped on x86_64-linux-gnu.  Ok to install?
> 
> 
> for  gcc/ChangeLog
> 
> 	* hash-set.h (add): Check that the inserted entry does not
> 	look empty.
OK once prereqs are installed.
jeff
diff mbox series

Patch

diff --git a/gcc/hash-set.h b/gcc/hash-set.h
index 76fa7f394561e..a98121a060eed 100644
--- a/gcc/hash-set.h
+++ b/gcc/hash-set.h
@@ -58,7 +58,11 @@  public:
       Key *e = m_table.find_slot_with_hash (k, Traits::hash (k), INSERT);
       bool existed = !Traits::is_empty (*e);
       if (!existed)
-	new (e) Key (k);
+	{
+	  new (e) Key (k);
+	  // Catch attempts to insert e.g. a NULL pointer.
+	  gcc_checking_assert (!Traits::is_empty (*e));
+	}
 
       return existed;
     }