]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
src/rrd_graph_helper.c: fix Coverity CID#13675 Dereference before null check
authorMarek Schimara <Marek.Schimara@bull.net>
Fri, 17 Jun 2016 07:47:25 +0000 (09:47 +0200)
committerMarek Schimara <Marek.Schimara@bull.net>
Thu, 23 Jun 2016 14:32:33 +0000 (16:32 +0200)
        CWE-476 / https://cwe.mitre.org/data/definitions/476.html

src/rrd_graph_helper.c

index 0f518eece1797ba23f0c52d87f1f1aff73f17dcb..3a6124824949835619043c0d0e330fee2fadc465 100644 (file)
@@ -140,20 +140,19 @@ int getMappedKeyValueArgument(const char* key,int flag, parsedargs_t* pa,
 }
 
 int getLong(const char* v,long *val,char**extra,int base) {
+  if (extra == NULL)
+    return 0;
+
   /* try to execute the parser */
   /* NOTE that this may be a bit different from the original parser */
   *extra=NULL;
   *val=strtol(v,extra,base);
   /* and error handling */
-  if (extra==NULL) {
-    return 0;
-  } else {
-    if (*extra==v) {
-      return -1; /* failed miserably */
-    }  else {
-      if ((*extra)[0]==0) { return 0; }
-      return 1; /* got extra bytes */
-    }
+  if (*extra==v) {
+    return -1; /* failed miserably */
+  }  else {
+    if ((*extra)[0]==0) { return 0; }
+    return 1; /* got extra bytes */
   }
   /* not found, so return error */
   return -2;