Re: [xml] Possible bug with xmlBufferPtr object?



On Thu, Jan 29, 2009 at 06:25:58PM -0500, Gilles Roy wrote:
I'm trying to make a copy of an in memory XML buffer. Based on the
sample code on the website (testWriter.c, the testXmlwriterMemory
function) I want to copy it to a buffer instead of writing to a file.
However, what I tried was:

char *xmldata = malloc(buf->use);
memcpy(xmldata, buf->content, buf->use);

However, this doesn't quite work. If buf->content is a string "abcd"
buf->use will be 4. This doesn't count for any kind of string
terminator. Should it?

Or does the application have to add the string terminator itself?

  The terminator may not be present in a buffer and it's definitely
not accounted for in the size, like in any classic C API, I can't see
why you're expecting this.

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel veillard com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/



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