From 7f68652ec01e15588c5accd597ae7988b54d487d Mon Sep 17 00:00:00 2001 From: ip_gpu Date: Mon, 30 Oct 2017 11:43:17 +0500 Subject: [PATCH] fixed from PVS-Studio: V522 There might be dereferencing of a potential null pointer 'h'. Check lines: 43, 8. alloc.c 43 V522 There might be dereferencing of a potential null pointer 'h->current'. Check lines: 46, 8. alloc.c 46 --- src/alloc.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/alloc.c b/src/alloc.c index 96590ed..eba440e 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -40,10 +40,14 @@ _pbcH_new(int pagesize) { cap *= 2; } struct heap * h = (struct heap *)_pbcM_malloc(sizeof(struct heap)); - h->current = (struct heap_page *)_pbcM_malloc(sizeof(struct heap_page) + cap); - h->size = cap; - h->used = 0; - h->current->next = NULL; + if (h) { + h->current = (struct heap_page *)_pbcM_malloc(sizeof(struct heap_page) + cap); + h->size = cap; + h->used = 0; + if (h->current) { + h->current->next = NULL; + } + } return h; }