From 701e2b8e53a00e4006f733c46442871e4cd8e6c0 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 1 Feb 2012 12:26:20 +0100 Subject: [PATCH] chcpu: check get_max_number_of_cpus() result properly Signed-off-by: Karel Zak --- sys-utils/chcpu.c | 2 +- sys-utils/lscpu.c | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/sys-utils/chcpu.c b/sys-utils/chcpu.c index 475c1cec66..29b7ab8965 100644 --- a/sys-utils/chcpu.c +++ b/sys-utils/chcpu.c @@ -248,7 +248,7 @@ int main(int argc, char *argv[]) textdomain(PACKAGE); maxcpus = get_max_number_of_cpus(); - if (maxcpus <= 0) + if ((int) maxcpus <= 0) errx(EXIT_FAILURE, _("cannot determine NR_CPUS; aborting")); if (path_exist(_PATH_SYS_CPU_ONLINE)) onlinecpus = path_cpulist(maxcpus, _PATH_SYS_CPU_ONLINE); diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c index a9ca2fe595..6a74c4eb78 100644 --- a/sys-utils/lscpu.c +++ b/sys-utils/lscpu.c @@ -383,9 +383,10 @@ read_basicinfo(struct lscpu_desc *desc, struct lscpu_modifier *mod) else if (mod->system == SYSTEM_LIVE) /* the root is '/' so we are working with data from the current kernel */ maxcpus = get_max_number_of_cpus(); - else - /* we are reading some /sys snapshot instead of the real /sys, - * let's use any crazy number... */ + + if (maxcpus <= 0) + /* error or we are reading some /sys snapshot instead of the + * real /sys, let's use any crazy number... */ maxcpus = desc->ncpus > 2048 ? desc->ncpus : 2048; /* get mask for online CPUs */ -- 2.47.3