]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Apply the MALLOC_ZERO_WORKS fixup to tor_realloc as well.
authorNick Mathewson <nickm@torproject.org>
Tue, 2 Sep 2014 16:53:11 +0000 (12:53 -0400)
committerNick Mathewson <nickm@torproject.org>
Tue, 2 Sep 2014 16:55:20 +0000 (12:55 -0400)
Also, make MALLOC_ZERO_WORKS never get applied when clang analyzer is
running.  This should make the clangalyzer a little happier.

src/common/util.c

index 16ff8e3a804224d650e1b649cd01ac7ea5dd7009..3f298cd9c457cc6b7aa51bb80e8ef8bf67e938ff 100644 (file)
 #include <sys/wait.h>
 #endif
 
+#ifdef __clang_analyzer__
+#undef MALLOC_ZERO_WORKS
+#endif
+
 /* =====
  * Assertion helper.
  * ===== */
@@ -231,6 +235,13 @@ tor_realloc_(void *ptr, size_t size DMALLOC_PARAMS)
 
   tor_assert(size < SIZE_T_CEILING);
 
+#ifndef MALLOC_ZERO_WORKS
+  /* Some libc mallocs don't work when size==0. Override them. */
+  if (size==0) {
+    size=1;
+  }
+#endif
+
 #ifdef USE_DMALLOC
   result = dmalloc_realloc(file, line, ptr, size, DMALLOC_FUNC_REALLOC, 0);
 #else