* [PATCH] lscpu: fix cppcheck warnings
@ 2014-09-12 18:11 Boris Egorov
0 siblings, 0 replies; 5+ messages in thread
From: Boris Egorov @ 2014-09-12 18:11 UTC (permalink / raw)
To: util-linux; +Cc: Boris Egorov
CppCheck founds a few wrong arguments in format strings and a NULL
pointer dereference.
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..d6fe1a5 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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] lscpu: fix cppcheck warnings
@ 2014-09-14 11:57 Andreas Henriksson
2014-09-14 12:04 ` Boris Egorov
2014-09-15 16:33 ` Boris Egorov
0 siblings, 2 replies; 5+ messages in thread
From: Andreas Henriksson @ 2014-09-14 11:57 UTC (permalink / raw)
To: Boris Egorov; +Cc: util-linux
Hello Boris Egorov!
I spotted something in your patch that doesn't look right to me.
[...]
> --- 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"))
^
Shouldn't the ! be here? --^
(alternatively: vendor && 0 == strcmp...)
> rc = HYPER_PARALLELS;
> done:
> free(buf);
[...]
Regards,
Andreas Henriksson
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] lscpu: fix cppcheck warnings
2014-09-14 11:57 Andreas Henriksson
@ 2014-09-14 12:04 ` Boris Egorov
2014-09-15 16:33 ` Boris Egorov
1 sibling, 0 replies; 5+ messages in thread
From: Boris Egorov @ 2014-09-14 12:04 UTC (permalink / raw)
To: Andreas Henriksson; +Cc: util-linux
Hello Andreas Henriksson!
Indeed, you are right. My fault. Should I send another patch, or amend
this one?
On 09/14/2014 06:57 PM, Andreas Henriksson wrote:
> Hello Boris Egorov!
>
> I spotted something in your patch that doesn't look right to me.
>
> [...]
>> --- 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"))
> ^
> Shouldn't the ! be here? --^
> (alternatively: vendor && 0 == strcmp...)
>
>> rc = HYPER_PARALLELS;
>> done:
>> free(buf);
> [...]
>
>
> Regards,
> Andreas Henriksson
--
Best regards,
Boris Egorov
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] lscpu: fix cppcheck warnings
2014-09-14 11:57 Andreas Henriksson
2014-09-14 12:04 ` Boris Egorov
@ 2014-09-15 16:33 ` Boris Egorov
2014-09-16 9:18 ` Karel Zak
1 sibling, 1 reply; 5+ messages in thread
From: Boris Egorov @ 2014-09-15 16:33 UTC (permalink / raw)
To: Andreas Henriksson; +Cc: util-linux, Boris Egorov
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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] lscpu: fix cppcheck warnings
2014-09-15 16:33 ` Boris Egorov
@ 2014-09-16 9:18 ` Karel Zak
0 siblings, 0 replies; 5+ messages in thread
From: Karel Zak @ 2014-09-16 9:18 UTC (permalink / raw)
To: Boris Egorov; +Cc: Andreas Henriksson, util-linux
On Mon, Sep 15, 2014 at 11:33:17PM +0700, Boris Egorov wrote:
> sys-utils/lscpu-dmi.c | 2 +-
> sys-utils/lscpu.c | 8 ++++----
> 2 files changed, 5 insertions(+), 5 deletions(-)
Good catch, thanks!
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-09-16 9:18 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-12 18:11 [PATCH] lscpu: fix cppcheck warnings Boris Egorov
-- strict thread matches above, loose matches on Subject: below --
2014-09-14 11:57 Andreas Henriksson
2014-09-14 12:04 ` Boris Egorov
2014-09-15 16:33 ` Boris Egorov
2014-09-16 9:18 ` Karel Zak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).