[libvirt] [PATCH] util: Fix coverity warings in virProcessGetAffinity

John Ferlan jferlan at redhat.com
Thu Jun 4 12:34:00 UTC 2015



On 06/04/2015 08:15 AM, Peter Krempa wrote:
> Refactor the code flow a bit more to clear coverity errors.
> 
> Store the cpu count in an intermediate variable and reuse it rather than
> caluclating the index.
> ---
>  src/util/virprocess.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/src/util/virprocess.c b/src/util/virprocess.c
> index a38cb75..c07e5cd 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,10 +504,10 @@ 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
>          if (CPU_ISSET_S(i, masklen, mask))

^^^ Coverity still complains here

No real change since previous...

John
>              ignore_value(virBitmapSetBit(ret, i));
> 




More information about the libvir-list mailing list