[libvirt] [PATCH] virCommand: Cleanup unnecessarily variables

Eric Blake eblake at redhat.com
Mon May 23 19:04:16 UTC 2011


On 05/22/2011 09:00 AM, Michal Prívozník wrote:
> On 22.05.2011 16:42, Michal Privoznik wrote:
>> ---
>> Building with ENABLE_DEBUG=0 showed more errors,
>> because VIR_DEBUG() get replaced with dummy 'do {} while(0)' statement,
>> and compiler complains about unused parameters. So if anybody knows
>> how to get rid of this ... Note that I am speaking about '...' part in
>> VIR_DEBUG_INT() definition.

>>                      if (inoff == inlen) {
>> -                        int tmpfd = infd;
>>                          if (VIR_CLOSE(infd) < 0)
>> -                            VIR_DEBUG("ignoring failed close on fd %d", tmpfd);
>> +                            VIR_DEBUG("ignoring failed close on fd %d", infd);

That won't work (infd is -1 at this point, not the value you meant to
print).  Either we don't care about the failure (and VIR_FORCE_CLOSE is
the better fix), or we do care about it, and should be using something
stronger than a VIR_DEBUG that can be compiled out.

Using VIR_FORCE_CLOSE is probably the right fix for this immediate
issue; another option would be marking the variable as (potentially)
unused, as in:

int tmpfd ATTRIBUTE_UNUSED;
tmpfd = infd;

But I can't help but wonder if the more generic issue could be solved by
making VIR_DEBUG() (when ENABLE_DEBUG=0) actually call a static inline
no-op varargs function, so that gcc treats it as using its arguments,
rather than the current situation of expanding to nothing and leaving
variables unused.

-- 
Eric Blake   eblake at redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20110523/0349846a/attachment-0001.sig>


More information about the libvir-list mailing list