summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2018-07-20 14:14:16 -0700
committerEdward Thomson <ethomson@edwardthomson.com>2018-09-22 19:15:47 +1000
commitc12ce2948c5a8e941a99961b992923db36072336 (patch)
treef6aa9c44733ea6cd1f044923ddf7281151a7f728
parent90a8a44385c2300fcae803e8ac1d6ee2b880b672 (diff)
downloadlibgit2-c12ce2948c5a8e941a99961b992923db36072336.tar.gz
buf tests: allocate a smaller size for the oom
On Linux (where we run valgrind) allocate a smaller buffer, but still an insanely large size. This will cause malloc to fail but will not cause valgrind to report a likely error with a negative-sized malloc. Keep the original buffer size on non-Linux platforms: this is well-tested on them and changing it may be problematic. On macOS, for example, using the new size causes `malloc` to print a warning to stderr.
-rw-r--r--tests/buf/oom.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/tests/buf/oom.c b/tests/buf/oom.c
index b9fd29cbb..16a03cc1a 100644
--- a/tests/buf/oom.c
+++ b/tests/buf/oom.c
@@ -1,10 +1,22 @@
#include "clar_libgit2.h"
#include "buffer.h"
-#if defined(GIT_ARCH_64)
-#define TOOBIG 0xffffffffffffff00
+/*
+ * We want to use some ridiculous size that `malloc` will fail with
+ * but that does not otherwise interfere with testing. On Linux, choose
+ * a number that is large enough to fail immediately but small enough
+ * that valgrind doesn't believe it to erroneously be a negative number.
+ * On macOS, choose a number that is large enough to fail immediately
+ * without having libc print warnings to stderr.
+ */
+#if defined(GIT_ARCH_64) && defined(__linux__)
+# define TOOBIG 0x0fffffffffffffff
+#elif defined(__linux__)
+# define TOOBIG 0x0fffffff
+#elif defined(GIT_ARCH_64)
+# define TOOBIG 0xffffffffffffff00
#else
-#define TOOBIG 0xffffff00
+# define TOOBIG 0xffffff00
#endif
/**