From: Guus Sliepen Date: Sun, 18 Oct 2015 11:45:16 +0000 (+0200) Subject: Fix check for return value of malloc(), allow initially zero length buffer. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=3c10b4a62f71cdc92e7dea3ace931ec1f497a660;p=utcp Fix check for return value of malloc(), allow initially zero length buffer. --- 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;