Re: [PATCHv3 5/6] Allow specifying --dirstat cut-off percentage as a floating point number
- From
Linus Torvalds <torvalds@linux-foundation.org>
- Date
- Apr 27, 2011, 08:37 UTC
- Message-ID
- <BANLkTi=xJXFKwzu4cCZAW_T2dXQ8wOq70w@mail.gmail.com>
- In-Reply-To
- <1303892653-3958-6-git-send-email-johan@herland.net>
On Wed, Apr 27, 2011 at 1:24 AM, Johan Herland <johan@herland.net> wrote:
Show 9 quoted lines
> + options->dirstat_permille = strtoul(p, &end, 10) * 10;
> p = end;
> + if (*p == '.' && isdigit(*(++p))) {
> + int permille = strtoul(p, &end, 10);
> + p = end;
> + while (permille >= 10)
> + permille /= 10; /* only use first digit */
> + options->dirstat_permille += permille;
> + }Heh. That's both unnecessarily complicated, and doesn't work.
It gets the wrong answer for something like "0.0001", since 'permille' in that case ends up starting out as '0001', ie just 1, so you never actually do that whole while-loop.
So the right approach is just something like
if (*p == '.' && isdigit(*++p)) {
/* only use first digit */
options->dirstat_permille += *p - '0';
/* .. and ignore any further digits */
while (isdigit(*++p))
/* nothing */;
}(totally untested, of course)
Linus