From f2ffea858cda7dfab072b4c85aceab8cf3b1098e Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Wed, 21 Mar 2007 15:24:56 +0000 Subject: [PATCH] * qemud/buf.c src/xml.c: clarified virBufferGrow (and bufferGrow) routines documentation and fixes a couple of places where this was misused as pointed by Daniel Berrange. Daniel --- ChangeLog | 6 ++++++ TODO | 1 + qemud/buf.c | 8 ++++---- src/xml.c | 8 ++++---- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7356eda5f3..a3b8df7c73 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Wed Mar 21 16:31:29 CET 2007 Daniel Veillard + + * qemud/buf.c src/xml.c: clarified virBufferGrow (and bufferGrow) + routines documentation and fixes a couple of places where this + was misused as pointed by Daniel Berrange. + Wed Mar 21 10:52:06 EST 2007 Daniel P. Berrange * acinclude.m4: Always use -Wp,-D_FORTIFY_SOURCE=2 -fexceptions diff --git a/TODO b/TODO index b739d7f327..7d21fae43c 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,6 @@ TODO: - libvirt_virDomainSetMemory should check memory is > 0 +- remove calls from sprintf and use snprintf - check how to better handle renaming of domains (xm rename and cache) - UUID lookup in hash.c diff --git a/qemud/buf.c b/qemud/buf.c index 61c5875cae..2ce2462a69 100644 --- a/qemud/buf.c +++ b/qemud/buf.c @@ -19,9 +19,9 @@ /** * bufferGrow: * @buf: the buffer - * @len: the minimum free size to allocate + * @len: the minimum free size to allocate on top of existing used space * - * Grow the available space of an XML buffer. + * Grow the available space of a buffer to at least @len bytes. * * Returns the new available space or -1 in case of error */ @@ -72,7 +72,7 @@ bufferAdd(bufferPtr buf, const char *str, int len) needSize = buf->use + len + 2; if (needSize > buf->size) { - if (!bufferGrow(buf, needSize)) { + if (!bufferGrow(buf, needSize - buf->use)) { return (-1); } } @@ -195,7 +195,7 @@ bufferStrcat(bufferPtr buf, ...) unsigned int needSize = buf->use + len + 2; if (needSize > buf->size) { - if (!bufferGrow(buf, needSize)) + if (!bufferGrow(buf, needSize - buf->use)) return -1; } memcpy(&buf->content[buf->use], str, len); diff --git a/src/xml.c b/src/xml.c index c67dc3521e..6ec4938fbe 100644 --- a/src/xml.c +++ b/src/xml.c @@ -43,9 +43,9 @@ virXMLError(virConnectPtr conn, virErrorNumber error, const char *info, int valu /** * virBufferGrow: * @buf: the buffer - * @len: the minimum free size to allocate + * @len: the minimum free size to allocate on top of existing used space * - * Grow the available space of an XML buffer. + * Grow the available space of an XML buffer to at least @len bytes. * * Returns the new available space or -1 in case of error */ @@ -99,7 +99,7 @@ virBufferAdd(virBufferPtr buf, const char *str, int len) needSize = buf->use + len + 2; if (needSize > buf->size) { - if (!virBufferGrow(buf, needSize)) { + if (!virBufferGrow(buf, needSize - buf->use)) { return (-1); } } @@ -200,7 +200,7 @@ virBufferStrcat(virBufferPtr buf, ...) unsigned int needSize = buf->use + len + 2; if (needSize > buf->size) { - if (!virBufferGrow(buf, needSize)) + if (!virBufferGrow(buf, needSize - buf->use)) return -1; } memcpy(&buf->content[buf->use], str, len);