Describe the bug
Compiling Redis 6.2.0 on a system without malloc_usable_size() or similar with USE_JEMALLOC=No results in a build failure. The following is seen on OpenBSD -current (amd64 with clang 10.0.1):
zmalloc.c:60:5: error: function-like macro 'sizeof' is not defined
#if PREFIX_SIZE > 0
^
zmalloc.c:56:22: note: expanded from macro 'PREFIX_SIZE'
#define PREFIX_SIZE (sizeof(size_t))
^
1 error generated.
https://github.com/redis/redis/blob/8e83bcd2acb18370e2d6cea3718339792322e80f/src/zmalloc.c#L60-L64
The issue is that at the preprocessing stage keywords like sizeof do not exist (see C11 6.10, footnote 166), so if HAVE_MALLOC_SIZE is not defined, the above conditional won't be accepted by either clang or gcc.
https://github.com/redis/redis/blob/8e83bcd2acb18370e2d6cea3718339792322e80f/src/zmalloc.c#L50-L58
To reproduce
Compile Redis 6.2.0 on a system without malloc_usable_size() or similar with USE_JEMALLOC=No.
Expected behavior
Redis compiles
Additional information
I think the following diff would make sense, which I can submit as a PR if that's acceptable. I expect all versions having a version of https://github.com/redis/redis/pull/8522 to be affected.
--- src/zmalloc.c.orig
+++ src/zmalloc.c
@@ -28,6 +28,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
+#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
@@ -57,7 +58,7 @@ void zlibc_free(void *ptr) {
#endif
#endif
-#if PREFIX_SIZE > 0
+#ifndef HAVE_MALLOC_SIZE
#define ASSERT_NO_SIZE_OVERFLOW(sz) assert((sz) + PREFIX_SIZE > (sz))
#else
#define ASSERT_NO_SIZE_OVERFLOW(sz)