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:
Jilles Tjoelker 2010-12-18 23:03:51 +00:00
parent 1a0b1eafd2
commit 79357531c8
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=216547
2 changed files with 6 additions and 2 deletions

View File

@ -74,12 +74,12 @@ int yylex(void);
return ARITH_NUM;
}
0[0-7]+ {
0[0-7]* {
yylval.l_value = strtoarith_t(yytext, NULL, 8);
return ARITH_NUM;
}
[0-9]+ {
[1-9][0-9]* {
yylval.l_value = strtoarith_t(yytext, NULL, 10);
return ARITH_NUM;
}

View File

@ -0,0 +1,4 @@
# $FreeBSD$
v=$( (eval ': $((08))') 2>&1 >/dev/null)
[ $? -ne 0 ] && [ -n "$v" ]