Bug 1416666 - Avoid doing a memset on a non-POD structure. r?waldo draft
authorAndi-Bogdan Postelnicu <bpostelnicu@mozilla.com>
Sat, 05 May 2018 07:11:35 +0300
changeset 791735 e622920319d4c383f5e229bce19debd20d61773c
parent 791409 8994f35fe5fc89f4e8f4e09579a6962f8a4a3e65
push id108893
push userbmo:bpostelnicu@mozilla.com
push dateSat, 05 May 2018 04:12:49 +0000
reviewerswaldo
bugs1416666
milestone61.0a1
Bug 1416666 - Avoid doing a memset on a non-POD structure. r?waldo MozReview-Commit-ID: Djf8EhIGDya
js/public/HashTable.h
--- a/js/public/HashTable.h
+++ b/js/public/HashTable.h
@@ -7,16 +7,17 @@
 #ifndef js_HashTable_h
 #define js_HashTable_h
 
 #include "mozilla/Alignment.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/Casting.h"
 #include "mozilla/HashFunctions.h"
+#include "mozilla/MemoryChecking.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/Move.h"
 #include "mozilla/Opaque.h"
 #include "mozilla/PodOperations.h"
 #include "mozilla/ReentrancyGuard.h"
 #include "mozilla/TemplateLib.h"
 #include "mozilla/TypeTraits.h"
 #include "mozilla/UniquePtr.h"
@@ -1665,24 +1666,25 @@ class HashTable : private AllocPolicy
 #ifdef JS_DEBUG
         mutationCount++;
 #endif
     }
 
   public:
     void clear()
     {
-        if (mozilla::IsPod<Entry>::value) {
-            memset(table, 0, sizeof(*table) * capacity());
-        } else {
-            uint32_t tableCapacity = capacity();
+        uint32_t tableCapacity = capacity();
+
+        if (!mozilla::IsPod<Entry>::value) {
             Entry* end = table + tableCapacity;
             for (Entry* e = table; e < end; ++e)
                 e->clear();
         }
+
+        MOZ_MAKE_MEM_UNDEFINED(table, sizeof(*table) * tableCapacity);
         removedCount = 0;
         entryCount = 0;
 #ifdef JS_DEBUG
         mutationCount++;
 #endif
     }
 
     void clearAndShrink()