]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: buffer: Don't treat missing truncation in virBufferTrim as usage error
authorPeter Krempa <pkrempa@redhat.com>
Thu, 24 Oct 2019 07:05:49 +0000 (09:05 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 24 Oct 2019 17:35:34 +0000 (19:35 +0200)
Usage errors in the virBuffer are hard to track anyways. Just trim
noting if the user requests the trimming string to be used without
providing it.

The change in the test proves that it's a no-op now.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/util/virbuffer.c
tests/virbuftest.c

index bcf9042573cc995464f813c5994d6fda5c7685bc..9a74ca78bb7a120a5e410f7da4140cd36ce5830b 100644 (file)
@@ -784,8 +784,6 @@ virBufferStrcat(virBufferPtr buf, ...)
  * if the current tail of the buffer matches @str; a non-negative @len
  * further limits how much of the tail is trimmed.  If @str is NULL, then
  * @len must be non-negative.
- *
- * Sets error to -1 (usage) if str is NULL and len is less than zero.
  */
 void
 virBufferTrim(virBufferPtr buf, const char *str, int len)
@@ -794,10 +792,8 @@ virBufferTrim(virBufferPtr buf, const char *str, int len)
 
     if (!buf || buf->error)
         return;
-    if (!str && len < 0) {
-        virBufferSetError(buf, -1);
+    if (!str && len < 0)
         return;
-    }
 
     if (len > 0 && len > buf->use)
         return;
index 385f016174ac066ac6945aafd9340bbc6c4204ea..8b8754adfa9f700feaece8df0b6ddc99240ae213 100644 (file)
@@ -163,6 +163,7 @@ static int testBufTrim(const void *data G_GNUC_UNUSED)
     virBufferTrim(buf, "a", 2);
 
     virBufferAddLit(buf, ",b,,");
+    virBufferTrim(buf, NULL, -1);
     virBufferTrim(buf, "b", -1);
     virBufferTrim(buf, "b,,", 1);
     virBufferTrim(buf, ",", -1);
@@ -178,12 +179,6 @@ static int testBufTrim(const void *data G_GNUC_UNUSED)
         goto cleanup;
     }
 
-    virBufferTrim(buf, NULL, -1);
-    if (virBufferError(buf) != -1) {
-        VIR_TEST_DEBUG("Usage error not flagged");
-        goto cleanup;
-    }
-
     ret = 0;
 
  cleanup: