]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
hash set: reject attempts to add empty values
authorAlexandre Oliva <oliva@adacore.com>
Thu, 29 Dec 2022 17:33:03 +0000 (14:33 -0300)
committerAlexandre Oliva <oliva@gnu.org>
Thu, 29 Dec 2022 17:39:47 +0000 (14:39 -0300)
Check, after adding a key to a hash set, that the entry does not look
empty.

for  gcc/ChangeLog

* hash-set.h (add): Check that the inserted entry does not
look empty.

gcc/hash-set.h

index 76fa7f394561e9e875d53f1acd533c4611f0f4a0..a98121a060eed65ebe792842494ed7472f8ed4cf 100644 (file)
@@ -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;
     }