[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Libvir] don't use virBufferAdd with string literals



On Mon, Feb 04, 2008 at 08:27:41PM +0100, Jim Meyering wrote:
> I noticed a little glitch here:
> 
>       src/xml.c:   virBufferAdd(buf, "(usbdevice tablet)", 13);
>       src/xml.c:   virBufferAdd(buf, "(usbdevice tablet)", 18);
> 
> So I mounted a campaign to remove all such uses of virBufferAdd
> and make sure no more sneak back in.
> First, I added this definition:
> 
>     #define virBufferAddLit(buf_, literal_string_) \
>       virBufferAdd (buf_, "" literal_string_ "", sizeof literal_string_ - 1)
> 
> The empty double quotes ensure that you get a syntax error if you
> pass anything other than a string literal in the 2nd parameter.
> 
> The idea being to change, e.g., the above examples to this:
> 
>     virBufferAddLit(buf, "(usbdevice tablet)");
> 
> FYI, I converted almost all of the uses of virBufferAdd like this:

This is great - every single place where virBufferAdd is used without
a 3rd param of '-'1 is a bug waiting to strike. So how about we now
remove the 3rd param from virBufferAdd, since it should only be used for
non-literals now & you don't know the length of those ahead of time
making the 3rd param useless.

Dan.
-- 
|=- Red Hat, Engineering, Emerging Technologies, Boston.  +1 978 392 2496 -=|
|=-           Perl modules: http://search.cpan.org/~danberr/              -=|
|=-               Projects: http://freshmeat.net/~danielpb/               -=|
|=-  GnuPG: 7D3B9505   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505  -=| 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]