sh: arith: Disallow decimal constants starting with 0 (containing 8 or 9).
Constants in arithmetic starting with 0 should be octal only. This avoids the following highly puzzling result: $ echo $((018-017)) 3 by making it an error instead.
This commit is contained in:
parent
2a8eefc56b
commit
84941f8297
@ -74,12 +74,12 @@ int yylex(void);
|
|||||||
return ARITH_NUM;
|
return ARITH_NUM;
|
||||||
}
|
}
|
||||||
|
|
||||||
0[0-7]+ {
|
0[0-7]* {
|
||||||
yylval.l_value = strtoarith_t(yytext, NULL, 8);
|
yylval.l_value = strtoarith_t(yytext, NULL, 8);
|
||||||
return ARITH_NUM;
|
return ARITH_NUM;
|
||||||
}
|
}
|
||||||
|
|
||||||
[0-9]+ {
|
[1-9][0-9]* {
|
||||||
yylval.l_value = strtoarith_t(yytext, NULL, 10);
|
yylval.l_value = strtoarith_t(yytext, NULL, 10);
|
||||||
return ARITH_NUM;
|
return ARITH_NUM;
|
||||||
}
|
}
|
||||||
|
4
tools/regression/bin/sh/expansion/arith8.0
Normal file
4
tools/regression/bin/sh/expansion/arith8.0
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# $FreeBSD$
|
||||||
|
|
||||||
|
v=$( (eval ': $((08))') 2>&1 >/dev/null)
|
||||||
|
[ $? -ne 0 ] && [ -n "$v" ]
|
Loading…
x
Reference in New Issue
Block a user