From: Nathan Moinvaziri Date: Mon, 28 Sep 2020 23:43:50 +0000 (-0700) Subject: Fixed dereference of possibly null head variable in test_deflate_set_header. X-Git-Tag: v2.0.0-RC1~44 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=982fc994018c00b323edb33c31ad666724523a20;p=thirdparty%2Fzlib-ng.git Fixed dereference of possibly null head variable in test_deflate_set_header. example.c:920:16: warning: dereference of possibly-NULL ‘head’ [CWE-690] [-Wanalyzer-possible-null-dereference] 920 | head->text = 1; | ~~~~~~~~~~~^~~ ‘test_deflate_set_header’: event 1 | | 906 | PREFIX(gz_header) *head = calloc(1, sizeof(PREFIX(gz_header))); | | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (1) this call could return NULL --- diff --git a/test/example.c b/test/example.c index 4010c91d..97ca0029 100644 --- a/test/example.c +++ b/test/example.c @@ -909,6 +909,11 @@ void test_deflate_set_header(unsigned char *compr, size_t comprLen) { size_t len = strlen(hello)+1; + if (head == NULL) { + printf("out of memory\n"); + exit(1); + } + c_stream.zalloc = zalloc; c_stream.zfree = zfree; c_stream.opaque = (voidpf)0;