]> git.meshlink.io Git - utcp/blobdiff - utcp.c
Fix check for return value of malloc(), allow initially zero length buffer.
[utcp] / 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;