[Toybox] Excluding octal.
Rob Landley
rob at landley.net
Tue Jul 1 17:17:04 PDT 2025
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.
Rob
P.S. The strstr() is so "seq 1 -1 -0x10" still works. :)
More information about the Toybox
mailing list