All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: "Daniel P. Berrange" <berrange@redhat.com>
Cc: Sage Weil <sage@newdream.net>,
	libvir-list@redhat.com, ceph-devel@vger.kernel.org
Subject: Re: [libvirt] [PATCH 4/5] buf: implement generic virBufferEscape
Date: Wed, 12 Oct 2011 11:09:04 -0600	[thread overview]
Message-ID: <4E95C9B0.5020205@redhat.com> (raw)
In-Reply-To: <20111011103935.GB16057@redhat.com>

On 10/11/2011 04:39 AM, Daniel P. Berrange wrote:
> On Mon, Sep 19, 2011 at 09:13:42PM -0700, Sage Weil wrote:
>> Implement a generic helper to escape a given set of characters with a
>> leading '\'.  Generalizes virBufferEscapeSexpr().
>>
>> Signed-off-by: Sage Weil<sage@newdream.net>
>> @@ -408,14 +428,13 @@ virBufferEscapeSexpr(const virBufferPtr buf,
>>       cur = str;
>>       out = escaped;
>>       while (*cur != 0) {
>> -        switch (*cur) {
>> -        case '\\':
>> -        case '\'':
>> -            *out++ = '\\';
>> -            /* fallthrough */
>> -        default:
>> -            *out++ = *cur;
>> +        for (p = toescape; *p; ++p) {
>> +            if (*cur == *p) {

strchr is slightly more efficient than hand-rolling this loop.

More importantly, you had a logic bug, where you replaced one hard-coded 
instance of "\\'", but not the other (the strcspn optimization).  Also, 
I tend to use "'" instead of "\'", although both work, since I favor 
concise code (I save my ramblings for my emails :).

>
> ACK, trivial isolated patch

I added you to AUTHORS, squashed this in, then pushed.

diff --git i/src/util/buf.c w/src/util/buf.c
index 7d0d2d3..5627d8f 100644
--- i/src/util/buf.c
+++ w/src/util/buf.c
@@ -383,7 +383,7 @@ virBufferEscapeSexpr(const virBufferPtr buf,
                       const char *format,
                       const char *str)
  {
-    virBufferEscape(buf, "\\\'", format, str);
+    virBufferEscape(buf, "\\'", format, str);
  }

  /**
@@ -414,7 +414,7 @@ virBufferEscape(const virBufferPtr buf,
          return;

      len = strlen(str);
-    if (strcspn(str, "\\'") == len) {
+    if (strcspn(str, toescape) == len) {
          virBufferAsprintf(buf, format, str);
          return;
      }
@@ -428,12 +428,8 @@ virBufferEscape(const virBufferPtr buf,
      cur = str;
      out = escaped;
      while (*cur != 0) {
-        for (p = toescape; *p; ++p) {
-            if (*cur == *p) {
-                *out++ = '\\';
-                break;
-            }
-        }
+        if (strchr(toescape, *cur))
+            *out++ = '\\';
          *out++ = *cur;
          cur++;
      }
-- 
Eric Blake   eblake@redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

  reply	other threads:[~2011-10-12 17:09 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-20  4:13 [PATCH 0/5 v2] Improve Ceph Qemu+RBD support Sage Weil
2011-09-20  4:13 ` [PATCH 1/5] secret: add Ceph secret type Sage Weil
2011-10-12 16:36   ` [libvirt] " Daniel P. Berrange
2011-09-20  4:13 ` [PATCH 2/5] storage: add authId, authDomain to virDomainDiskDef Sage Weil
2011-10-12 16:38   ` [libvirt] " Daniel P. Berrange
2011-09-20  4:13 ` [PATCH 3/5] qemu: pass virConnectPtr into Domain{Attach,Detach}* Sage Weil
2011-10-12 16:40   ` [libvirt] [PATCH 3/5] qemu: pass virConnectPtr into Domain{Attach, Detach}* Daniel P. Berrange
2011-09-20  4:13 ` [PATCH 4/5] buf: implement generic virBufferEscape Sage Weil
2011-10-11 10:39   ` [libvirt] " Daniel P. Berrange
2011-10-12 17:09     ` Eric Blake [this message]
2011-09-20  4:13 ` [PATCH 5/5] qemu/rbd: improve rbd device specification Sage Weil
2011-10-12 16:48   ` [libvirt] " Daniel P. Berrange
2011-09-27 20:40 ` [PATCH 0/5 v2] Improve Ceph Qemu+RBD support Sage Weil
2011-10-07 11:39 ` Wido den Hollander
2011-10-07 12:17   ` [libvirt] " Daniel P. Berrange
2011-10-12 16:33 ` Daniel P. Berrange
2011-10-12 16:45   ` Sage Weil

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4E95C9B0.5020205@redhat.com \
    --to=eblake@redhat.com \
    --cc=berrange@redhat.com \
    --cc=ceph-devel@vger.kernel.org \
    --cc=libvir-list@redhat.com \
    --cc=sage@newdream.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.