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

Peter Krempa pkrempa at redhat.com
Thu Jun 4 15:13:11 UTC 2015


On Thu, Jun 04, 2015 at 08:34:00 -0400, John Ferlan wrote:
> 
> 
> 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...

Would you mind sharing the error after applying this patch?

Peter
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20150604/0f8b3f33/attachment-0001.sig>


More information about the libvir-list mailing list