]> git.meshlink.io Git - utcp/commitdiff
Fix check for return value of malloc(), allow initially zero length buffer.
authorGuus Sliepen <guus@meshlink.io>
Sun, 18 Oct 2015 11:45:16 +0000 (13:45 +0200)
committerGuus Sliepen <guus@sliepen.org>
Sun, 2 Jul 2017 10:02:03 +0000 (12:02 +0200)
utcp.c

diff --git a/utcp.c b/utcp.c
index e6f6cf9ede28360df84fad0161b0a993e01a3c0f..9434c70170e5a6f9b9de5f0b8743e7fed9914223 100644 (file)
--- 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;