From: Dan Kegel Date: Sat, 13 Jun 2020 19:17:46 +0000 (+0000) Subject: infcover.c: assert that we avoid zero-length allocations; fixes #593 X-Git-Tag: 1.9.9-b1~216 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ee28753685d62117f8ef4ef8b94ba101a5cd1e96;p=thirdparty%2Fzlib-ng.git infcover.c: assert that we avoid zero-length allocations; fixes #593 --- diff --git a/test/infcover.c b/test/infcover.c index 10baaad5..9f98bd5c 100644 --- a/test/infcover.c +++ b/test/infcover.c @@ -242,8 +242,11 @@ static void mem_done(PREFIX3(stream) *strm, char *prefix) { static unsigned char *h2b(const char *hex, unsigned *len) { unsigned char *in, *re; unsigned next, val; + unsigned inlen; - in = malloc((strlen(hex) + 1) >> 1); + inlen = (strlen(hex) + 1) >> 1; + assert(inlen != 0); /* tell static analyzer we won't call malloc(0) */ + in = malloc(inlen); if (in == NULL) return NULL; next = 0; @@ -264,6 +267,7 @@ static unsigned char *h2b(const char *hex, unsigned *len) { } while (*hex++); /* go through the loop with the terminating null */ if (len != NULL) *len = next; + assert(next != 0); /* tell static analyzer we won't call realloc(in, 0) */ re = realloc(in, next); return re == NULL ? in : re; }