]> git.codecow.com Git - Monocypher.git/commitdiff
Don't try to malloc() zero bytes
authorLoup Vaillant <loup@loup-vaillant.fr>
Tue, 19 Jun 2018 22:53:37 +0000 (00:53 +0200)
committerLoup Vaillant <loup@loup-vaillant.fr>
Tue, 19 Jun 2018 22:53:37 +0000 (00:53 +0200)
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.

tests/test.c

index 33e7b9201a0595d54b2648744c15013fba3ddc5c..cc76c9b102358b2d2b58f05dd7fb7aecf59be268 100644 (file)
 
 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);