From: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
To: Eric Sandeen <sandeen@redhat.com>
Cc: kreijack@inwind.it, Wang Shilong <wangshilong1991@gmail.com>,
linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 1/4] Btrfs-progs: new helper to parse string to u64 for btrfs
Date: Thu, 20 Feb 2014 08:48:59 +0800 [thread overview]
Message-ID: <530550FB.1090709@cn.fujitsu.com> (raw)
In-Reply-To: <5304E891.8040606@redhat.com>
On 02/20/2014 01:23 AM, Eric Sandeen wrote:
> On 2/19/14, 10:31 AM, Goffredo Baroncelli wrote:
> ...
>
>
>> The error message says that the value is out of range. But doesn't tell which
>> is the parameter involved.
>> If you have a command which has several arguments, and the user pass a string
>> instead of a number, the error returned doesn't tell which argument is wrong.
>> This is the reason of my complaint.
>>
>> At least add a fourth parameter which contains the name of the parameter
>> parsed in order to improve the error message.
>>
>> I.E.
>>
>> subvol_id = btrfs_strtoull(argv[i], 10, "subvolume ID");
>>
>> If the user pass a path instead of a number the error message would be
>>
>> ERROR: xxxx is not a valid unsigned long long integer for the parameter 'subvolume ID'.
>>
>> Or something like that.
> I'm not so sure that this is needed. Adding it makes the code a little more complicated,
> and requires each caller to send in a string which may get out of sync with the actual
> argument name (or the manpage, or the help/usage text).
>
> The user has *just* typed it in, so it won't be too hard to see which one
> was wrong even without naming the parameter, i.e. -
>
> # btrfs foo-command 12345 0 123notanumber
> Error: 123notanumber is not a valid numeric value
>
> or
>
> # btrfs baz-command 0xFFFFFFFFFFFFFFFF 12345 0
> Error: numeric value 0xFFFFFFFFFFFFFFFF is too large.
>
> would probably suffice, without bothering to name the parameter.
Sounds more reasonable.:-)
>
> I'd also suggest not referring to "unsigned long long" or "out of range" which
> might not mean much to people who aren't programmers; "not a valid value"
> or "too large" might be clearer.
Will update it.
>
> Also, what if someone enters a negative number? Right now it happily
> accepts it and converts it to an unsigned value:
>
> # ./test-64bit -123
> Parsed as 18446744073709551493
So Let's add a '-' check before calling strtoull. something like:
if (str[0] == '-')
fprintf(stderr, "ERROR: this may be a negative integer: %s\n", str);
Thanks,
Wang
>
> but an inadvertent negative sign might lead to highly unexpected results.
>
> Just my $0.02.
>
> -Eric
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
next prev parent reply other threads:[~2014-02-20 0:50 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-19 11:17 [PATCH 0/4] Btrfs-progs: cleanups: new helper for parsing string to u64 Wang Shilong
2014-02-19 11:17 ` [PATCH 1/4] Btrfs-progs: new helper to parse string to u64 for btrfs Wang Shilong
2014-02-19 14:46 ` Stefan Behrens
2014-02-19 14:59 ` Wang Shilong
2014-02-19 15:47 ` Goffredo Baroncelli
2014-02-19 16:08 ` Wang Shilong
2014-02-19 16:31 ` Goffredo Baroncelli
2014-02-19 16:43 ` Wang Shilong
2014-02-19 17:23 ` Eric Sandeen
2014-02-20 0:48 ` Wang Shilong [this message]
2014-02-20 16:42 ` David Sterba
2014-02-19 11:17 ` [PATCH 2/4] Btrfs-progs: switch to btrfs_strtoull() part1 Wang Shilong
2014-02-19 11:17 ` [PATCH 3/4] Btrfs-progs: switch to btrfs_strtoull() part2 Wang Shilong
2014-02-19 11:17 ` [PATCH 4/4] Btrfs-progs: switch to btrfs_strtoull() part3 Wang Shilong
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=530550FB.1090709@cn.fujitsu.com \
--to=wangsl.fnst@cn.fujitsu.com \
--cc=kreijack@inwind.it \
--cc=linux-btrfs@vger.kernel.org \
--cc=sandeen@redhat.com \
--cc=wangshilong1991@gmail.com \
/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).