]> granicus.if.org Git - llvm/commitdiff
BitVector: Fix undefined behaviour
authorMatthias Braun <matze@braunis.de>
Fri, 20 Jan 2017 04:23:08 +0000 (04:23 +0000)
committerMatthias Braun <matze@braunis.de>
Fri, 20 Jan 2017 04:23:08 +0000 (04:23 +0000)
Calling reset() on an empty BitVector would call memset with a nullptr
argument which is undefined behaviour.

This should fix the sanitizer bot.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292575 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/BitVector.h

index cf3756d0d9c1f619514871983f28cd9989110ca5..cb318199ec778b852c4eb27a62e93a67cd66923d 100644 (file)
@@ -539,7 +539,8 @@ private:
   }
 
   void init_words(BitWord *B, unsigned NumWords, bool t) {
-    memset(B, 0 - (int)t, NumWords*sizeof(BitWord));
+    if (NumWords > 0)
+      memset(B, 0 - (int)t, NumWords*sizeof(BitWord));
   }
 
   template<bool AddBits, bool InvertMask>