[Toybox] Excluding octal.

enh enh at google.com
Mon Jul 7 09:27:17 PDT 2025


On Tue, Jul 1, 2025 at 8:17 PM Rob Landley <rob at landley.net> wrote:
>
> I've had this in my tree forever, but haven't checked it in. Anybody
> have an objection to me pulling the trigger?
>
> --- a/lib/lib.c
> +++ b/lib/lib.c
> @@ -312,7 +312,8 @@ long long atolx(char *numstr)
>     char *c = numstr, *suffixes="cwbkmgtpe", *end;
>     long long val;
>
> -  val = xstrtol(numstr, &c, 0);
> +  // exclude octal to avoid confusion
> +  val = xstrtol(numstr, &c, strstr(numstr, "0x") ? 0 : 10);
>     if (c != numstr && *c && (end = strchr(suffixes, tolower(*c)))) {
>       int shift = end-suffixes-2;
>       ++c;
>
> I don't _think_ it'll break anything? I've gotten multiple bug reports
> from people being confused by octal. It was really a thing for 6 bit
> hardware like the PDP-10 back in the 1960s (before ASCII took over),
> which was eliminated by the falling cost of RAM making the ability to
> represent upper AND lowercase letters at the same time more important
> than squeezing 25% more uncompressed text into the same number of bits.
>
> Unix file permissions preserve its PDP-7 heritage in amber, but don't
> use this codepath to parse their input.

yeah, that seems like the only special case where this is useful, but
if that's already taken care of ... sgtm.

> Rob
>
> P.S. The strstr() is so "seq 1 -1 -0x10" still works. :)
> _______________________________________________
> Toybox mailing list
> Toybox at lists.landley.net
> http://lists.landley.net/listinfo.cgi/toybox-landley.net


More information about the Toybox mailing list