Avoid implementation-defined calloc of 0 bytes
authorEric Biggers <ebiggers3@gmail.com>
Tue, 26 Mar 2013 17:32:08 +0000 (12:32 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Tue, 26 Mar 2013 17:32:08 +0000 (12:32 -0500)
programs/imagex.c

index c3ab4b7..dd1a124 100644 (file)
@@ -551,7 +551,9 @@ parse_source_list(tchar **source_list_contents_p, size_t source_list_nchars,
                nlines++;
        }
 
-       sources = calloc(nlines, sizeof(*sources));
+       /* Always allocate at least 1 slot, just in case the implementation of
+        * calloc() returns NULL if 0 bytes are requested. */
+       sources = calloc(nlines ?: 1, sizeof(*sources));
        if (!sources)
                goto oom;
        p = source_list_contents;