From: Peter Krempa Date: Thu, 4 Jun 2015 12:13:15 +0000 (+0200) Subject: util: Make virProcessGetAffinity more readable and fix coverity warning X-Git-Tag: v1.2.17-rc1~214 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b0d2e31c5fa7e61b486a0fff4ee22b898f7caf01;p=thirdparty%2Flibvirt.git util: Make virProcessGetAffinity more readable and fix coverity warning Store the cpu count in an intermediate variable and reuse it rather than caluclating the index. Additionally add a coverity silencing comment. --- diff --git a/src/util/virprocess.c b/src/util/virprocess.c index 59598edf5a..b47df0f349 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -474,12 +474,14 @@ virProcessGetAffinity(pid_t pid) size_t i; cpu_set_t *mask; size_t masklen; + size_t ncpus; virBitmapPtr ret = NULL; # ifdef CPU_ALLOC /* 262144 cpus ought to be enough for anyone */ - masklen = CPU_ALLOC_SIZE(1024 << 8); - mask = CPU_ALLOC(1024 << 8); + ncpus = 1024 << 8; + masklen = CPU_ALLOC_SIZE(ncpus); + mask = CPU_ALLOC(ncpus); if (!mask) { virReportOOMError(); @@ -488,6 +490,7 @@ virProcessGetAffinity(pid_t pid) CPU_ZERO_S(masklen, mask); # else + ncpus = 1024; if (VIR_ALLOC(mask) < 0) return NULL; @@ -501,11 +504,12 @@ virProcessGetAffinity(pid_t pid) goto cleanup; } - if (!(ret = virBitmapNew(masklen * 8))) + if (!(ret = virBitmapNew(ncpus))) goto cleanup; - for (i = 0; i < masklen * 8; i++) { + for (i = 0; i < ncpus; i++) { # ifdef CPU_ALLOC + /* coverity[overrun-local] */ if (CPU_ISSET_S(i, masklen, mask)) ignore_value(virBitmapSetBit(ret, i)); # else