Static analysis flags some occasions of unchecked sscanf return value.

Cc: Yasunori Goto <[email protected]>
Signed-off-by: Dan Williams <[email protected]>
---
 util/json.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/util/json.c b/util/json.c
index d1ee351546b9..0c92c3b49c71 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,

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

Reply via email to