[libvirt] [PATCH 7/7] util: Avoid Coverity FORWARD_NULL

Peter Krempa pkrempa at redhat.com
Wed Jul 1 14:30:30 UTC 2015


On Wed, Jul 01, 2015 at 10:03:51 -0400, John Ferlan wrote:
> Avoid a false positive since Coverity find a path in virResizeN which
> could return 0 prior to the allocation of memory and thus flags a
> possible NULL dereference. Instead use multiple loops to first count
> the number of matches, perform one allocation, and then again search
> for matches.  It's a 'n' string comparisons and allocations versus
> 2*'n' string comparisons and one allocation.

Another option would be to alloc *ret to nparams and fill only the
matched ones leaving a part of the array unused. Since this will be
used mainly in cases where n will be a rather small number (I think
libvirt is able to support ~250 disks max) the memory overhead won't be
noticable.

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/20150701/008ae031/attachment-0001.sig>


More information about the libvir-list mailing list