From 982fc994018c00b323edb33c31ad666724523a20 Mon Sep 17 00:00:00 2001 From: Nathan Moinvaziri Date: Mon, 28 Sep 2020 16:43:50 -0700 Subject: [PATCH] Fixed dereference of possibly null head variable in test_deflate_set_header. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- test/example.c | 5 +++++ 1 file changed, 5 insertions(+) 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; -- 2.47.3