From 0350e2dd936fbca4a911f096462e26af83469b81 Mon Sep 17 00:00:00 2001 From: tchetch Date: Mon, 6 Oct 2014 16:19:45 +0200 Subject: - Use of calloc instead of malloc - Test for NULL after allocation --- src/chunk.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/chunk.h') diff --git a/src/chunk.h b/src/chunk.h index f37a2f3..015bbf9 100644 --- a/src/chunk.h +++ b/src/chunk.h @@ -59,10 +59,11 @@ static inline unsigned char *chunk_to_cstr(chunk *c) { unsigned char *str; - str = malloc(c->len + 1); - memcpy(str, c->data, c->len); - str[c->len] = 0; - + str = calloc(c->len + 1, sizeof(*str)); + if(str != NULL) { + memcpy(str, c->data, c->len); + str[c->len] = 0; + } return str; } -- cgit v1.2.3