From 57fbcd2b29aa74423d47a9efd783a1508ab1bfc5 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sat, 11 Dec 2021 11:13:00 +0000 Subject: malloc.c: check allocation sizes against PTRDIFF_MAX. I don't expect this to actually come up in any circumstance, but it prevents a warning in some versions of gcc that would otherwise arise from the use of 'int' to compute the input size: if gcc isn't confident that the int is positive, then it complains that possible inputs to malloc might be in the region of 2^64 - (small multiple of a negative 32-bit int). I would hope malloc would fail in any case on such an input, so failing a couple of lines earlier makes no important difference. Annoyingly, stdint.h is missing in my NestedVM build setup (though it has stdbool.h - it's not _totally_ C90). So I have to check that at cmake time. Also, removed the #defines for smalloc and friends from the tree234 test mode. These were needed in the old build system, when tree234-test was built ad-hoc without being linked against malloc.c. But now tree234-test links against the same utils library as everything else, and can use the real smalloc - and doing so prevents another of these warnings when compiling with -flto. --- tree234.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'tree234.c') diff --git a/tree234.c b/tree234.c index 587389f..136f6e2 100644 --- a/tree234.c +++ b/tree234.c @@ -43,9 +43,6 @@ static void logprintf(const char *fmt, ...) va_end(ap); } #define LOG(x) (logprintf x) -#define smalloc malloc -#define srealloc realloc -#define sfree free #else #define LOG(x) #endif -- cgit v1.1