]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
* src/buf.c: applied patch from Masayuki Sunou fixing a loop
authorDaniel Veillard <veillard@redhat.com>
Thu, 30 Aug 2007 13:12:44 +0000 (13:12 +0000)
committerDaniel Veillard <veillard@redhat.com>
Thu, 30 Aug 2007 13:12:44 +0000 (13:12 +0000)
  due to an error in growing buffers.
Daniel

ChangeLog
src/buf.c

index 2f607ff18306e1a90aa4a2b48278d009c8c7a64a..6a72989b8be2e641a82f44ed2f7ac076e1b7275c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Thu Aug 30 15:11:44 CEST 2007 Daniel Veillard <veillard@redhat.com>
+
+       * src/buf.c: applied patch from Masayuki Sunou fixing a loop
+         due to an error in growing buffers.
+
 Wed Aug 29 14:43:00 BST 2007 Richard W.M. Jones <rjones@redhat.com>
 
        * src/xen_internal.c (xenHypervisorDomainInterfaceStats): Swap
index 678a7107907ebdf3a5917da32430a43acada6851..192f0644011d1f2300ba6a510f56fd4c8286d71e 100644 (file)
--- a/src/buf.c
+++ b/src/buf.c
@@ -159,7 +159,7 @@ virBufferContentAndFree (virBufferPtr buf)
 int
 virBufferVSprintf(virBufferPtr buf, const char *format, ...)
 {
-    int size, count;
+    int size, count, grow_size;
     va_list locarg, argptr;
 
     if ((format == NULL) || (buf == NULL)) {
@@ -172,7 +172,8 @@ virBufferVSprintf(virBufferPtr buf, const char *format, ...)
                                locarg)) < 0) || (count >= size - 1)) {
         buf->content[buf->use] = 0;
         va_end(locarg);
-        if (virBufferGrow(buf, 1000) < 0) {
+        grow_size = (count > 1000) ? count : 1000;
+        if (virBufferGrow(buf, grow_size) < 0) {
             return (-1);
         }
         size = buf->size - buf->use - 1;
@@ -198,7 +199,7 @@ virBufferVSprintf(virBufferPtr buf, const char *format, ...)
 int
 virBufferEscapeString(virBufferPtr buf, const char *format, const char *str)
 {
-    int size, count, len;
+    int size, count, len, grow_size;
     char *escaped, *out;
     const char *cur;
 
@@ -248,7 +249,8 @@ virBufferEscapeString(virBufferPtr buf, const char *format, const char *str)
     while (((count = snprintf(&buf->content[buf->use], size, format,
                               (char *)escaped)) < 0) || (count >= size - 1)) {
         buf->content[buf->use] = 0;
-        if (virBufferGrow(buf, 1000) < 0) {
+        grow_size = (count > 1000) ? count : 1000;
+        if (virBufferGrow(buf, grow_size) < 0) {
            free(escaped);
             return (-1);
         }