Avoid zero length memset error
[oota-llvm.git] / include / llvm / Support / Allocator.h
index 5f3b284532de5b2bf311a2cba9875371ae2feaa9..9ea57039a8465b07ee3f3fc8ab644d10cd52dda4 100644 (file)
@@ -318,8 +318,10 @@ private:
 #ifndef NDEBUG
       // Poison the memory so stale pointers crash sooner.  Note we must
       // preserve the Size and NextPtr fields at the beginning.
-      sys::Memory::setRangeWritable(*I, AllocatedSlabSize);
-      memset(*I, 0xCD, AllocatedSlabSize);
+      if (AllocatedSlabSize != 0) {
+        sys::Memory::setRangeWritable(*I, AllocatedSlabSize);
+        memset(*I, 0xCD, AllocatedSlabSize);
+      }
 #endif
       Allocator.Deallocate(*I, AllocatedSlabSize);
     }