mirror of
git://c9x.me/qbe.git
synced 2026-04-05 09:59:47 +00:00
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:
parent
7ac9722ccb
commit
8ff0651552
7
parse.c
7
parse.c
@ -215,12 +215,15 @@ getint()
|
|||||||
n = 0;
|
n = 0;
|
||||||
c = fgetc(inf);
|
c = fgetc(inf);
|
||||||
m = (c == '-');
|
m = (c == '-');
|
||||||
if (m)
|
if (m) {
|
||||||
c = fgetc(inf);
|
c = fgetc(inf);
|
||||||
|
if (!isdigit(c))
|
||||||
|
err("integer expected");
|
||||||
|
}
|
||||||
do {
|
do {
|
||||||
n = 10*n + (c - '0');
|
n = 10*n + (c - '0');
|
||||||
c = fgetc(inf);
|
c = fgetc(inf);
|
||||||
} while ('0' <= c && c <= '9');
|
} while (isdigit(c));
|
||||||
ungetc(c, inf);
|
ungetc(c, inf);
|
||||||
if (m)
|
if (m)
|
||||||
n = 1 + ~n;
|
n = 1 + ~n;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user