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

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



On Tue, Feb 05, 2008 at 04:02:32PM +0000, Daniel P. Berrange wrote:
> 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

  Hum, that could be used in a very valid way for example to add only the
prefix of a string or if you know you have a non 0 terminated string.

Daniel

-- 
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard      | virtualization library  http://libvirt.org/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine  http://rpmfind.net/


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