From 3c10b4a62f71cdc92e7dea3ace931ec1f497a660 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Sun, 18 Oct 2015 13:45:16 +0200 Subject: [PATCH] Fix check for return value of malloc(), allow initially zero length buffer. --- utcp.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/utcp.c b/utcp.c index e6f6cf9..9434c70 100644 --- a/utcp.c +++ b/utcp.c @@ -197,9 +197,11 @@ static ssize_t buffer_copy(struct buffer *buf, void *data, size_t offset, size_t static bool buffer_init(struct buffer *buf, uint32_t len, uint32_t maxlen) { memset(buf, 0, sizeof *buf); - buf->data = malloc(len); - if(!len) - return false; + if(len) { + buf->data = malloc(len); + if(!buf->data) + return false; + } buf->size = len; buf->maxsize = maxlen; return true; -- 2.39.5