]> git.eshelyaron.com Git - emacs.git/commitdiff
Re-port dump_bitset_clear to -fsanitize=undefined
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 7 Aug 2019 01:39:20 +0000 (18:39 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 7 Aug 2019 01:39:58 +0000 (18:39 -0700)
* src/pdumper.c (dump_bitset_clear): Skip the memset if the
size is zero, because in that case the destination might be NULL.
This fixes a bug introduced in 2019-07-26T06:17:52Zeggert@cs.ucla.edu.
Add a comment to make the bug less likely to reoccur.

src/pdumper.c

index e0ddc1c8088364508e48ce7eab6be33245f7bcb7..326a346a6328beca1a8ff4f62b5808a62e6dada2 100644 (file)
@@ -4931,7 +4931,10 @@ dump_bitset_set_bit (struct dump_bitset *bitset, size_t bit_number)
 static void
 dump_bitset_clear (struct dump_bitset *bitset)
 {
-  memset (bitset->bits, 0, bitset->number_words * sizeof bitset->bits[0]);
+  /* Skip the memset if bitset->number_words == 0, because then bitset->bits
+     might be NULL and the memset would have undefined behavior.  */
+  if (bitset->number_words)
+    memset (bitset->bits, 0, bitset->number_words * sizeof bitset->bits[0]);
 }
 
 struct pdumper_loaded_dump_private