Blob Blame History Raw
ndctl: fix static analysis report, unchecked sscanf

BZ: 

commit 9dc0d660414d6da0f1cd89c80c94128b90603aa7
Author: Dan Williams <dan.j.williams@intel.com>
Date:   Mon Oct 2 08:59:56 2017 -0700

    ndctl: fix static analysis report, unchecked sscanf
    
    Static analysis flags some occasions of unchecked sscanf return value.
    
    Cc: Yasunori Goto <y-goto@jp.fujitsu.com>
    Signed-off-by: Dan Williams <dan.j.williams@intel.com>

diff --git a/util/json.c b/util/json.c
index d1ee351..0c92c3b 100644
--- a/util/json.c
+++ b/util/json.c
@@ -374,11 +374,12 @@ static int compare_dimm_number(const void *p1, const void *p2)
 	const char *dimm2_name = ndctl_dimm_get_devname(dimm2);
 	int num1, num2;
 
-	sscanf(dimm1_name, "nmem%d", &num1);
-	sscanf(dimm2_name, "nmem%d", &num2);
+	if (sscanf(dimm1_name, "nmem%d", &num1) != 1)
+		num1 = 0;
+	if (sscanf(dimm2_name, "nmem%d", &num2) != 1)
+		num2 = 0;
 
 	return num1 - num2;
-
 }
 
 static struct json_object *badblocks_to_jdimms(struct ndctl_region *region,