Skip to content

Commit

Permalink
sh: arith: Disallow decimal constants starting with 0 (containing 8 o…
Browse files Browse the repository at this point in the history
…r 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.
  • Loading branch information
jillest committed Dec 18, 2010
1 parent 1a0b1ea commit 7935753
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions bin/sh/arith_lex.l
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions tools/regression/bin/sh/expansion/arith8.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# $FreeBSD$

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

0 comments on commit 7935753

Please sign in to comment.