All of lore.kernel.org
 help / color / mirror / Atom feed
From: Boris Egorov <egorov@linux.com>
To: Andreas Henriksson <andreas@fatal.se>
Cc: util-linux@vger.kernel.org, Boris Egorov <egorov@linux.com>
Subject: [PATCH] lscpu: fix cppcheck warnings
Date: Mon, 15 Sep 2014 23:33:17 +0700	[thread overview]
Message-ID: <1410798797-23769-1-git-send-email-egorov@linux.com> (raw)
In-Reply-To: <20140914115745.GA20978@fatal.se>

CppCheck founds a few wrong arguments in format strings and a NULL
pointer dereference.

Amended version with fixed strcmp() usage.

Signed-off-by: Boris Egorov <egorov@linux.com>
---
 sys-utils/lscpu-dmi.c | 2 +-
 sys-utils/lscpu.c     | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/sys-utils/lscpu-dmi.c b/sys-utils/lscpu-dmi.c
index 6c870a1..0e497d1 100644
--- a/sys-utils/lscpu-dmi.c
+++ b/sys-utils/lscpu-dmi.c
@@ -161,7 +161,7 @@ static int hypervisor_from_dmi_table(uint32_t base, uint16_t len,
 	else if (manufacturer && strstr(manufacturer, "HITACHI") &&
 					product && strstr(product, "LPAR"))
 		rc = HYPER_HITACHI;
-	else if (!vendor && strcmp(vendor, "Parallels"))
+	else if (vendor && !strcmp(vendor, "Parallels"))
 		rc = HYPER_PARALLELS;
 done:
 	free(buf);
diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c
index 9965eeb..8827424 100644
--- a/sys-utils/lscpu.c
+++ b/sys-utils/lscpu.c
@@ -1182,12 +1182,12 @@ get_cell_data(struct lscpu_desc *desc, int idx, int col,
 	case COL_CORE:
 		if (cpuset_ary_isset(cpu, desc->coremaps,
 				     desc->ncores, setsize, &i) == 0)
-			snprintf(buf, bufsz, "%zd", i);
+			snprintf(buf, bufsz, "%zu", i);
 		break;
 	case COL_SOCKET:
 		if (cpuset_ary_isset(cpu, desc->socketmaps,
 				     desc->nsockets, setsize, &i) == 0)
-			snprintf(buf, bufsz, "%zd", i);
+			snprintf(buf, bufsz, "%zu", i);
 		break;
 	case COL_NODE:
 		if (cpuset_ary_isset(cpu, desc->nodemaps,
@@ -1197,7 +1197,7 @@ get_cell_data(struct lscpu_desc *desc, int idx, int col,
 	case COL_BOOK:
 		if (cpuset_ary_isset(cpu, desc->bookmaps,
 				     desc->nbooks, setsize, &i) == 0)
-			snprintf(buf, bufsz, "%zd", i);
+			snprintf(buf, bufsz, "%zu", i);
 		break;
 	case COL_CACHE:
 	{
@@ -1210,7 +1210,7 @@ get_cell_data(struct lscpu_desc *desc, int idx, int col,
 
 			if (cpuset_ary_isset(cpu, ca->sharedmaps,
 					     ca->nsharedmaps, setsize, &i) == 0) {
-				int x = snprintf(p, sz, "%zd", i);
+				int x = snprintf(p, sz, "%zu", i);
 				if (x <= 0 || (size_t) x + 2 >= sz)
 					return NULL;
 				p += x;
-- 
2.1.0


  parent reply	other threads:[~2014-09-15 16:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-14 11:57 [PATCH] lscpu: fix cppcheck warnings Andreas Henriksson
2014-09-14 12:04 ` Boris Egorov
2014-09-15 16:33 ` Boris Egorov [this message]
2014-09-16  9:18   ` Karel Zak
  -- strict thread matches above, loose matches on Subject: below --
2014-09-12 18:11 Boris Egorov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1410798797-23769-1-git-send-email-egorov@linux.com \
    --to=egorov@linux.com \
    --cc=andreas@fatal.se \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.