diff mbox

[RFC,v2,4/9] rbd: Clean up after the previous commit

Message ID 1490377482-13337-5-git-send-email-armbru@redhat.com
State New
Headers show

Commit Message

Markus Armbruster March 24, 2017, 5:44 p.m. UTC
This code in qemu_rbd_parse_filename()

    found_str = qemu_rbd_next_tok(p, '\0', &p);
    p = found_str;

has no effect.  Drop it, and simplify qemu_rbd_next_tok().

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 block/rbd.c | 24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)

Comments

Eric Blake March 24, 2017, 6:44 p.m. UTC | #1
On 03/24/2017 12:44 PM, Markus Armbruster wrote:
> This code in qemu_rbd_parse_filename()
> 
>     found_str = qemu_rbd_next_tok(p, '\0', &p);

This says to take a string starting at p, modify it in place, update p
to point past the delimiter (well, to nowhere since the delimiter of
'\0' means it is the last token parsed), and return the original
starting into found_str....

>     p = found_str;

...and this says to revert the change to p (why we had to pass &p
instead of NULL is beyond me).  Furthermore, reading the modifications
that qemu_rbd_next_tok() does in place (namely, looking for \ escape
sequences), it doesn't do any when delimiter is '\0'.  Prior to patch 3,
it was therefore useful as an idiom for length checking - but as you
killed even that aspect, I agree with your assessment that it is now a
no-op.

> 
> has no effect.  Drop it, and simplify qemu_rbd_next_tok().
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  block/rbd.c | 24 +++++++++---------------
>  1 file changed, 9 insertions(+), 15 deletions(-)
> 

Reviewed-by: Eric Blake <eblake@redhat.com>
diff mbox

Patch

diff --git a/block/rbd.c b/block/rbd.c
index 0fea348..182a5a3 100644
--- a/block/rbd.c
+++ b/block/rbd.c
@@ -104,19 +104,17 @@  static char *qemu_rbd_next_tok(char *src, char delim, char **p)
 
     *p = NULL;
 
-    if (delim != '\0') {
-        for (end = src; *end; ++end) {
-            if (*end == delim) {
-                break;
-            }
-            if (*end == '\\' && end[1] != '\0') {
-                end++;
-            }
-        }
+    for (end = src; *end; ++end) {
         if (*end == delim) {
-            *p = end + 1;
-            *end = '\0';
+            break;
         }
+        if (*end == '\\' && end[1] != '\0') {
+            end++;
+        }
+    }
+    if (*end == delim) {
+        *p = end + 1;
+        *end = '\0';
     }
     return src;
 }
@@ -177,10 +175,6 @@  static void qemu_rbd_parse_filename(const char *filename, QDict *options,
         goto done;
     }
 
-    found_str = qemu_rbd_next_tok(p, '\0', &p);
-
-    p = found_str;
-
     /* The following are essentially all key/value pairs, and we treat
      * 'id' and 'conf' a bit special.  Key/value pairs may be in any order. */
     while (p) {