From: Loup Vaillant Date: Tue, 19 Jun 2018 22:53:37 +0000 (+0200) Subject: Don't try to malloc() zero bytes X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=65a1bac8d5944c0584e56c9915bdbbd5e037cb1e;p=Monocypher.git Don't try to malloc() zero bytes Some platforms refuse to allocate zero bytes. This causes the entire test suite to fail miserably. To avoid this, we now fake success, and return the NULL pointer. It won't be dereferenced anyway. --- diff --git a/tests/test.c b/tests/test.c index 33e7b92..cc76c9b 100644 --- a/tests/test.c +++ b/tests/test.c @@ -20,6 +20,12 @@ static void* alloc(size_t size) { + if (size == 0) { + // Some systems refuse to allocate zero bytes. + // So we don't. Instead, we just return a non-sensical pointer. + // It shouldn't be dereferenced anyway. + return NULL; + } void *buf = malloc(size); if (buf == NULL) { fprintf(stderr, "Allocation failed: 0x%zx bytes\n", size);