From: Eric Sandeen <sandeen@redhat.com>
To: Ilya Dryomov <idryomov@gmail.com>
Cc: kreijack@inwind.it, Goffredo Baroncelli <kreijack@gmail.com>,
linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 17/17 V2] btrfs-progs: replace strtok_r with strsep
Date: Tue, 26 Feb 2013 14:46:30 -0600 [thread overview]
Message-ID: <512D1F26.7020804@redhat.com> (raw)
In-Reply-To: <20130226204040.GA1993@zambezi.lan>
On 2/26/13 2:40 PM, Ilya Dryomov wrote:
> On Tue, Feb 26, 2013 at 02:20:30PM -0600, Eric Sandeen wrote:
>> The coverity runs had a false positive complaining that save_ptr
>> is uninitialized in the call to strtok_r.
>>
>> We could initialize it, but Zach points out that just using
>> strsep is a lot simpler if there's only one delimiter,
>> so just switch to that.
>>
>> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
>> ---
>>
>> V2: Remove accidentally-added debug printfs, thanks Geoffredo!
>>
>> diff --git a/cmds-balance.c b/cmds-balance.c
>> index b671e1d..cfbb8eb 100644
>> --- a/cmds-balance.c
>> +++ b/cmds-balance.c
>> @@ -67,11 +67,8 @@ static int parse_one_profile(const char *profile, u64 *flags)
>> static int parse_profiles(char *profiles, u64 *flags)
>> {
>> char *this_char;
>> - char *save_ptr;
>>
>> - for (this_char = strtok_r(profiles, "|", &save_ptr);
>> - this_char != NULL;
>> - this_char = strtok_r(NULL, "|", &save_ptr)) {
>> + while ((this_char = strsep(&profiles, "|"))) {
>> if (parse_one_profile(this_char, flags))
>> return 1;
>> }
>> @@ -136,14 +133,11 @@ static int parse_filters(char *filters, struct btrfs_balance_args *args)
>> {
>> char *this_char;
>> char *value;
>> - char *save_ptr;
>>
>> if (!filters)
>> return 0;
>>
>> - for (this_char = strtok_r(filters, ",", &save_ptr);
>> - this_char != NULL;
>> - this_char = strtok_r(NULL, ",", &save_ptr)) {
>> + while ((this_char = strsep(&filters , ","))) {
>
> ^^^ whitespace
>
>
> One of the differences between strtok() and strsep() is that the former
> allows multiple delimiters between two tokens. With strsep(), this
>
> btrfs balance -dfoo1=bar1,,,foo2=bar2 <mnt>
>
> fails with error, whereas with strtok() it passes. I don't have a
> strong opinion here (this has been loosely modeled on the way mount(8)
> handles -o options), but might it be better to just initialize save_ptr?
> (And yes, I know that strsep() is better ;))
I don't really care much either way, TBH. Initializing it seems a little
bit magic, but with a comment as to why, it'd be fine. If you did it this
way intentionally to allow the above format, and changing it would break
expectations, then I'll happily just initialize save_ptr.
(And, I realize that lots of these changes are pedantic and seemingly
pointless, but we've gotten the static checker errors down from over 100
to under 30 and dropping; the more noise we remove the more likely we are
to pay attention to the output and catch actual errors. At least that's
my feeling; if people think this is getting to be pointless churn, I'm
ok with that, too).
Thanks for the review,
-Eric
p.s. Zach made me do it. ;)
> Thanks,
>
> Ilya
>
next prev parent reply other threads:[~2013-02-26 20:46 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-25 22:54 [PATCH 00/17] btrfs-progs: More misc fixes & cleanups Eric Sandeen
2013-02-25 22:54 ` [PATCH 01/17] btrfs-progs: Unify size-parsing Eric Sandeen
2013-02-25 23:26 ` Zach Brown
2013-02-25 23:37 ` Eric Sandeen
2013-02-26 0:26 ` Zach Brown
2013-02-26 18:50 ` Goffredo Baroncelli
2013-02-26 20:17 ` Eric Sandeen
2013-02-26 21:15 ` Goffredo Baroncelli
2013-02-25 22:54 ` [PATCH 02/17] btrfs-progs: fix btrfs_get_subvol cut/paste error Eric Sandeen
2013-02-25 22:54 ` [PATCH 03/17] btrfs-progs: Remove write-only var fdres in cmd_dev_stats() Eric Sandeen
2013-02-25 22:54 ` [PATCH 04/17] btrfs-progs: btrfs_list_get_path_rootid error handling Eric Sandeen
2013-02-25 22:54 ` [PATCH 05/17] btrfs-progs: avoid double-free in __btrfs_map_block Eric Sandeen
2013-02-25 22:54 ` [PATCH 06/17] btrfs-progs: fix open error test in cmd_start_replace Eric Sandeen
2013-02-25 22:54 ` [PATCH 07/17] btrfs-progs: fix close of error fd in scrub cancel Eric Sandeen
2013-02-25 22:54 ` [PATCH 08/17] btrfs-progs: more scrub cancel error handling Eric Sandeen
2013-02-25 22:54 ` [PATCH 09/17] btrfs-progs: free memory before error exit in read_whole_eb Eric Sandeen
2013-02-25 22:54 ` [PATCH 10/17] btrfs-progs: don't call close on error fd Eric Sandeen
2013-02-25 22:54 ` [PATCH 11/17] btrfs-progs: provide positive errno to strerror in cmd_restore Eric Sandeen
2013-02-25 22:54 ` [PATCH 12/17] btrfs-progs: free allocated di_args in cmd_start_replace Eric Sandeen
2013-02-25 22:54 ` [PATCH 13/17] btrfs-progs: close fd on cmd_subvol_get_default return Eric Sandeen
2013-02-25 22:54 ` [PATCH 14/17] btrfs-progs: fix mem leak in resolve_root Eric Sandeen
2013-02-26 0:36 ` Shilong Wang
2013-02-26 4:36 ` Eric Sandeen
2013-02-27 13:03 ` David Sterba
2013-02-27 13:12 ` Shilong Wang
2013-02-25 22:54 ` [PATCH 15/17] btrfs-progs: Tidy up resolve_root Eric Sandeen
2013-02-25 22:54 ` [PATCH 16/17] btrfs-progs: fix fd leak in cmd_subvol_set_default Eric Sandeen
2013-02-26 18:46 ` Goffredo Baroncelli
2013-02-26 20:10 ` Eric Sandeen
2013-02-26 21:04 ` Goffredo Baroncelli
2013-02-27 12:38 ` David Sterba
2013-02-25 22:54 ` [PATCH 17/17] btrfs-progs: replace strtok_r with strsep Eric Sandeen
2013-02-26 18:47 ` Goffredo Baroncelli
2013-02-26 20:13 ` Eric Sandeen
2013-02-26 20:20 ` [PATCH 17/17 V2] " Eric Sandeen
2013-02-26 20:40 ` Ilya Dryomov
2013-02-26 20:46 ` Eric Sandeen [this message]
2013-02-26 21:07 ` Ilya Dryomov
2013-02-26 21:50 ` [PATCH 17/17 V3] btrfs-progs: initialize save_ptr prior to strtok_r Eric Sandeen
2013-02-27 13:54 ` [PATCH 00/17] btrfs-progs: More misc fixes & cleanups David Sterba
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=512D1F26.7020804@redhat.com \
--to=sandeen@redhat.com \
--cc=idryomov@gmail.com \
--cc=kreijack@gmail.com \
--cc=kreijack@inwind.it \
--cc=linux-btrfs@vger.kernel.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).