Message ID | 150696061891.21689.14927545469089860105.stgit@dwillia2-desk3.amr.corp.intel.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 9dc0d660414d |
Headers | show |
> 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> > --- > 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, > > Good catch. Thanks! Reviewed-by: Yasunori Goto<y-goto@jp.fujitsu.com>
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,
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> --- util/json.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)