Skip to contentSkip to conversation

master - coverity: helping coverity with NULL pointer

PATCH Zdenek Kabelac 1 participant 1 message Feb 26, 2016

lore
Share & tools
lore
#0 lore raw
Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=2988fa3c21cf84071446bc11cb61d5b8507c088c
Commit:        2988fa3c21cf84071446bc11cb61d5b8507c088c
Parent:        85a593c1911f5c7ef5a8de38178b085c02ad3965
Author:        Zdenek Kabelac <[email protected]>
AuthorDate:    Fri Feb 26 10:15:24 2016 +0100
Committer:     Zdenek Kabelac <[email protected]>
CommitterDate: Fri Feb 26 10:21:36 2016 +0100

coverity: helping coverity with NULL pointer

Helping with understanding we will not try to deref NULL pointer, as if the sizes are initialized to NULL it also means 'mem' would be NULL, but thats too hard to model so make it obvious.

---
 libdaemon/client/config-util.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
libdaemon/client/config-util.c +2 -2
index 7a7dfed..e262182 100644
@@ -366,9 +366,9 @@ int buffer_append(struct buffer *buf, const char *string)
 {
 	int len = strlen(string);
 
-	if ((buf->allocated - buf->used <= len) &&
+	if ((!buf->mem || (buf->allocated - buf->used <= len)) &&
 	    !buffer_realloc(buf, len + 1))
-                return 0;
+		return 0;
 
 	strcpy(buf->mem + buf->used, string);
 	buf->used += len;