From patchwork Mon Oct 2 16:10:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 9981003 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4A0FE60375 for ; Mon, 2 Oct 2017 16:16:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3BDCD200E7 for ; Mon, 2 Oct 2017 16:16:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 30C192842A; Mon, 2 Oct 2017 16:16:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2CC32200E7 for ; Mon, 2 Oct 2017 16:16:44 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 251F321F2AF9A; Mon, 2 Oct 2017 09:13:25 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.43; helo=mga05.intel.com; envelope-from=dan.j.williams@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 8A2FE21F303EB for ; Mon, 2 Oct 2017 09:13:24 -0700 (PDT) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga105.fm.intel.com with ESMTP; 02 Oct 2017 09:16:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.42,470,1500966000"; d="scan'208"; a="1201314355" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.125]) by fmsmga001.fm.intel.com with ESMTP; 02 Oct 2017 09:16:43 -0700 Subject: [ndctl PATCH] ndctl: fix static analysis report, unchecked sscanf From: Dan Williams To: linux-nvdimm@lists.01.org Date: Mon, 02 Oct 2017 09:10:18 -0700 Message-ID: <150696061891.21689.14927545469089860105.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.17.1-9-g687f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yasunori Goto Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP Static analysis flags some occasions of unchecked sscanf return value. Cc: Yasunori Goto Signed-off-by: Dan Williams Reviewed-by: Yasunori Goto --- 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,