parse: deny non-digit after minus in getint

also: '0' <= c <= '9' -> isdigit(c)
Signed-off-by: willow <im@purring.fyi>
This commit is contained in:
willow 2026-02-19 19:30:07 -05:00 committed by Quentin Carbonneaux
parent 7ac9722ccb
commit 8ff0651552

View File

@ -215,12 +215,15 @@ getint()
n = 0;
c = fgetc(inf);
m = (c == '-');
if (m)
if (m) {
c = fgetc(inf);
if (!isdigit(c))
err("integer expected");
}
do {
n = 10*n + (c - '0');
c = fgetc(inf);
} while ('0' <= c && c <= '9');
} while (isdigit(c));
ungetc(c, inf);
if (m)
n = 1 + ~n;