Re: [PATCHv3 5/6] Allow specifying --dirstat cut-off percentage as a floating point number

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Apr 27, 2011 at 1:24 AM, Johan Herland <johan@xxxxxxxxxxx> wrote:
> +                       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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]