Fix undefined behavior in gperftools

ubsan catches it.

Change-Id: I70468e05414518fd0818ee38b2dd3cf5aeee6b9c
diff --git a/third_party/gperftools/src/base/low_level_alloc.cc b/third_party/gperftools/src/base/low_level_alloc.cc
index 4d2ae8d..4a40816 100644
--- a/third_party/gperftools/src/base/low_level_alloc.cc
+++ b/third_party/gperftools/src/base/low_level_alloc.cc
@@ -104,7 +104,7 @@
 
 // Return a random integer n:  p(n)=1/(2**n) if 1 <= n; p(n)=0 if n < 1.
 static int Random() {
-  static int32 r = 1;         // no locking---it's not critical
+  static uint32 r = 1;         // no locking---it's not critical
   ANNOTATE_BENIGN_RACE(&r, "benign race, not critical.");
   int result = 1;
   while ((((r = r*1103515245 + 12345) >> 30) & 1) == 0) {
diff --git a/third_party/gperftools/src/tests/sampler_test.cc b/third_party/gperftools/src/tests/sampler_test.cc
index cd64b0f..df94ee0 100755
--- a/third_party/gperftools/src/tests/sampler_test.cc
+++ b/third_party/gperftools/src/tests/sampler_test.cc
@@ -604,7 +604,7 @@
     CHECK_GE(q, 0); // << rnd << "  " << prng_mod_power;
   }
   // Test some potentially out of bounds value for rnd
-  for (int i = 1; i <= 66; i++) {
+  for (int i = 1; i <= 63; i++) {
     rnd = one << i;
     double q = (rnd >> (prng_mod_power - 26)) + 1.0;
     LOG(INFO) << "rnd = " << rnd << " i=" << i << " q=" << q;
diff --git a/third_party/gperftools/src/tests/tcmalloc_unittest.cc b/third_party/gperftools/src/tests/tcmalloc_unittest.cc
index 69698bc..1831168 100644
--- a/third_party/gperftools/src/tests/tcmalloc_unittest.cc
+++ b/third_party/gperftools/src/tests/tcmalloc_unittest.cc
@@ -725,9 +725,9 @@
 // that we used the tcmalloc version of the call, and not the libc.
 // Note the ... in the hook signature: we don't care what arguments
 // the hook takes.
-#define MAKE_HOOK_CALLBACK(hook_type)                                   \
+#define MAKE_HOOK_CALLBACK(hook_type, args...)                          \
   static volatile int g_##hook_type##_calls = 0;                                 \
-  static void IncrementCallsTo##hook_type(...) {                        \
+  static void IncrementCallsTo##hook_type(args) {                       \
     g_##hook_type##_calls++;                                            \
   }                                                                     \
   static void Verify##hook_type##WasCalled() {                          \
@@ -744,12 +744,14 @@
   }
 
 // We do one for each hook typedef in malloc_hook.h
-MAKE_HOOK_CALLBACK(NewHook);
-MAKE_HOOK_CALLBACK(DeleteHook);
-MAKE_HOOK_CALLBACK(MmapHook);
-MAKE_HOOK_CALLBACK(MremapHook);
-MAKE_HOOK_CALLBACK(MunmapHook);
-MAKE_HOOK_CALLBACK(SbrkHook);
+MAKE_HOOK_CALLBACK(NewHook, const void*, size_t);
+MAKE_HOOK_CALLBACK(DeleteHook, const void*);
+MAKE_HOOK_CALLBACK(MmapHook, const void*, const void*, size_t, int, int, int,
+                   off_t);
+MAKE_HOOK_CALLBACK(MremapHook, const void*, const void*, size_t, size_t, int,
+                   const void*);
+MAKE_HOOK_CALLBACK(MunmapHook, const void *, size_t);
+MAKE_HOOK_CALLBACK(SbrkHook, const void *, ptrdiff_t);
 
 static void TestAlignmentForSize(int size) {
   fprintf(LOGSTREAM, "Testing alignment of malloc(%d)\n", size);
@@ -1279,9 +1281,9 @@
     VerifyMunmapHookWasCalled();
     close(fd);
 #else   // this is just to quiet the compiler: make sure all fns are called
-    IncrementCallsToMmapHook();
-    IncrementCallsToMunmapHook();
-    IncrementCallsToMremapHook();
+    IncrementCallsToMmapHook(NULL, NULL, 0, 0, 0, 0, 0);
+    IncrementCallsToMunmapHook(NULL, 0);
+    IncrementCallsToMremapHook(NULL, NULL, 0, 0, 0, NULL);
     VerifyMmapHookWasCalled();
     VerifyMremapHookWasCalled();
     VerifyMunmapHookWasCalled();
@@ -1302,7 +1304,7 @@
     CHECK(p1 != NULL);
     CHECK_EQ(g_SbrkHook_calls, 0);
 #else   // this is just to quiet the compiler: make sure all fns are called
-    IncrementCallsToSbrkHook();
+    IncrementCallsToSbrkHook(NULL, 0);
     VerifySbrkHookWasCalled();
 #endif