Call function pointers with the right type

I think it's undefined behavior, but it's definitely weird. ubsan
complains too.
This commit is contained in:
Brian Silverman 2016-03-01 17:57:33 -05:00 committed by Brian
parent e0fa28ef7d
commit 126d4582c1

View File

@ -725,9 +725,9 @@ static void TestNothrowNew(void* (*func)(size_t, const std::nothrow_t&)) {
// 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, ...) \
static volatile int g_##hook_type##_calls = 0; \
static void IncrementCallsTo##hook_type(...) { \
static void IncrementCallsTo##hook_type(__VA_ARGS__) { \
g_##hook_type##_calls++; \
} \
static void Verify##hook_type##WasCalled() { \
@ -744,12 +744,14 @@ static void TestNothrowNew(void* (*func)(size_t, const std::nothrow_t&)) {
}
// 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);
@ -1282,9 +1284,9 @@ static int RunAllTests(int argc, char** argv) {
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();
@ -1305,7 +1307,7 @@ static int RunAllTests(int argc, char** argv) {
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