chiark / gitweb /
journal-remote-parse: avoid passing null to memchr
authorThomas Hindoe Paaboel Andersen <phomes@gmail.com>
Sat, 5 Apr 2014 19:05:22 +0000 (21:05 +0200)
committerThomas Hindoe Paaboel Andersen <phomes@gmail.com>
Sun, 6 Apr 2014 09:55:20 +0000 (11:55 +0200)
Found with scan-build

src/journal/journal-remote-parse.c

index 142de0ed1f004a56a25e83378c43f9ec58fc0413..239ff381975703c920b0a9ad6d1e2348fe3905c6 100644 (file)
@@ -40,7 +40,7 @@ void source_free(RemoteSource *source) {
 
 static int get_line(RemoteSource *source, char **line, size_t *size) {
         ssize_t n, remain;
-        char *c;
+        char *c = NULL;
         char *newbuf = NULL;
         size_t newsize = 0;
 
@@ -49,7 +49,9 @@ static int get_line(RemoteSource *source, char **line, size_t *size) {
         assert(source->filled <= source->size);
         assert(source->buf == NULL || source->size > 0);
 
-        c = memchr(source->buf, '\n', source->filled);
+        if (source->buf)
+                c = memchr(source->buf, '\n', source->filled);
+
         if (c != NULL)
                 goto docopy;