Skip to contentSkip to conversation

lscpu: fix cppcheck warnings

PATCH In review Andreas Henriksson 3 participants 4 messages Sep 14, 2014 – Sep 16, 2014 Util-Linux package

lore
Share & tools
lore
#0 lore raw

Hello Boris Egorov!

I spotted something in your patch that doesn't look right to me.

[...]

sys-utils/lscpu-dmi.c static int hypervisor_from_dmi_table(uint32_t base, uint16_t len, · line 164

Quoted 8 lines
sys-utils/lscpu-dmi.c +1 -1
@@ -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"))
                           ^

Shouldn't the ! be here? --^
(alternatively: vendor && 0 == strcmp...)

sys-utils/lscpu-dmi.c static int hypervisor_from_dmi_table(uint32_t base, uint16_t len, · line 167

Quoted 3 lines
sys-utils/lscpu-dmi.c +0 -0
 		rc = HYPER_PARALLELS;
 done:
 	free(buf);

[...]

Regards,
Andreas Henriksson

#1 lore raw

Hello Andreas Henriksson!

Indeed, you are right. My fault. Should I send another patch, or amend this one?

Quoted 25 lines · Andreas Henriksson

Hello Boris Egorov!

I spotted something in your patch that doesn't look right to me.

[...]

sys-utils/lscpu-dmi.c static int hypervisor_from_dmi_table(uint32_t base, uint16_t len, · line 164

Quoted 8 lines
sys-utils/lscpu-dmi.c +1 -1
@@ -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"))
                           ^

Shouldn't the ! be here? --^
(alternatively: vendor && 0 == strcmp...)

sys-utils/lscpu-dmi.c static int hypervisor_from_dmi_table(uint32_t base, uint16_t len, · line 167

Quoted 3 lines
sys-utils/lscpu-dmi.c +0 -0
 		rc = HYPER_PARALLELS;
 done:
 	free(buf);

[...]

Regards,
Andreas Henriksson

Signature · 3 lines
Best regards,

Boris Egorov
#2 lore raw

PATCH 1/1 lscpu: fix cppcheck warnings

In reply to Andreas Henriksson

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

Amended version with fixed strcmp() usage.

---
 sys-utils/lscpu-dmi.c | 2 +-
 sys-utils/lscpu.c     | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)
sys-utils/lscpu-dmi.c +1 -1
index 6c870a1..0e497d1 100644
@@ -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);
sys-utils/lscpu.c +4 -4
index 9965eeb..8827424 100644
@@ -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;
Signature · 1 line
2.1.0
maintainer
#3 lore raw
Quoted 3 lines · Boris Egorov
 sys-utils/lscpu-dmi.c | 2 +-
 sys-utils/lscpu.c     | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)

Good catch, thanks!

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com