qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Connor Kuehl <ckuehl@redhat.com>
To: Max Reitz <mreitz@redhat.com>, qemu-block@nongnu.org
Cc: kwolf@redhat.com, dillaman@redhat.com, qemu-devel@nongnu.org
Subject: Re: [PATCH v2 2/2] block/rbd: Add an escape-aware strchr helper
Date: Fri, 9 Apr 2021 09:05:14 -0500	[thread overview]
Message-ID: <ad6beb34-7e80-3e60-7c2d-faa2836febf9@redhat.com> (raw)
In-Reply-To: <bc5865f8-bb7f-58b5-5f1c-9ec3e5c09ad9@redhat.com>

On 4/6/21 9:24 AM, Max Reitz wrote:
> On 01.04.21 23:01, Connor Kuehl wrote:
>> [..]
>> diff --git a/block/rbd.c b/block/rbd.c
>> index 9071a00e3f..c0e4d4a952 100644
>> --- a/block/rbd.c
>> +++ b/block/rbd.c
>> @@ -134,6 +134,22 @@ static char *qemu_rbd_next_tok(char *src, char 
>> delim, char **p)
>>       return src;
>>   }
>> +static char *qemu_rbd_strchr(char *src, char delim)
>> +{
>> +    char *p;
>> +
>> +    for (p = src; *p; ++p) {
>> +        if (*p == delim) {
>> +            return p;
>> +        }
>> +        if (*p == '\\') {
>> +            ++p;
>> +        }
>> +    }
>> +
>> +    return NULL;
>> +}
>> +
> 
> So I thought you could make qemu_rbd_do_next_tok() to do this.  (I 
> didn’t say you should, but bear with me.)  That would be possible by 
> giving it a new parameter (e.g. @find), and if that is set, return @end 
> if *end == delim after the loop, and NULL otherwise.
> 
> Now, if you add wrapper functions to make it nice, there’s not much more 
> difference in lines added compared to just adding a new function, but it 
> does mean your function should basically be the same as 
> qemu_rbd_next_tok(), except that no splitting happens, that there is no 
> *p, and that @end is returned instead of @src.

Do you have a strong preference for this? I agree that 
qemu_rbd_next_tok() could grow this functionality, but I think it'd be 
simpler to keep it separate in the form of qemu_rbd_strchr().

> 
> So there is one difference, and that is that qemu_rbd_next_tok() has 
> this condition to skip escaped characters:
> 
>      if (*end == '\\' && end[1] != '\0') {
> 
> where qemu_rbd_strchr() has only:
> 
>      if (*p == '\\') {
> 
> And I think qemu_rbd_next_tok() is right; if the string in question has 
> a trailing backslash, qemu_rbd_strchr() will ignore the final NUL and 
> continue searching past the end of the string.

Aha, good catch. I'll fix this up.

Thank you,

Connor



  reply	other threads:[~2021-04-09 14:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-01 21:01 [PATCH v2 0/2] Fix segfault in qemu_rbd_parse_filename Connor Kuehl
2021-04-01 21:01 ` [PATCH v2 1/2] iotests/231: Update expected deprecation message Connor Kuehl
2021-04-01 21:01 ` [PATCH v2 2/2] block/rbd: Add an escape-aware strchr helper Connor Kuehl
2021-04-06 14:24   ` Max Reitz
2021-04-09 14:05     ` Connor Kuehl [this message]
2021-04-09 14:19       ` Max Reitz

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=ad6beb34-7e80-3e60-7c2d-faa2836febf9@redhat.com \
    --to=ckuehl@redhat.com \
    --cc=dillaman@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).