diff options
author | jilles <jilles@FreeBSD.org> | 2010-12-18 23:03:51 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2010-12-18 23:03:51 +0000 |
commit | 84941f8297970e3618d7e98cdbef942031b9a596 (patch) | |
tree | 25ca73deea96a1e4bb9d3b97235aa742e7f61254 | |
parent | 2a8eefc56b6eda956a168d2be7354df603b97b24 (diff) | |
download | FreeBSD-src-84941f8297970e3618d7e98cdbef942031b9a596.zip FreeBSD-src-84941f8297970e3618d7e98cdbef942031b9a596.tar.gz |
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.
-rw-r--r-- | bin/sh/arith_lex.l | 4 | ||||
-rw-r--r-- | tools/regression/bin/sh/expansion/arith8.0 | 4 |
2 files changed, 6 insertions, 2 deletions
diff --git a/bin/sh/arith_lex.l b/bin/sh/arith_lex.l index b4a04d3..f93608a 100644 --- a/bin/sh/arith_lex.l +++ b/bin/sh/arith_lex.l @@ -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; } diff --git a/tools/regression/bin/sh/expansion/arith8.0 b/tools/regression/bin/sh/expansion/arith8.0 new file mode 100644 index 0000000..2d03e50 --- /dev/null +++ b/tools/regression/bin/sh/expansion/arith8.0 @@ -0,0 +1,4 @@ +# $FreeBSD$ + +v=$( (eval ': $((08))') 2>&1 >/dev/null) +[ $? -ne 0 ] && [ -n "$v" ] |