Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 18 Dec 2010 23:03:52 +0000 (UTC)
From:      Jilles Tjoelker <jilles@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r216547 - in head: bin/sh tools/regression/bin/sh/expansion
Message-ID:  <201012182303.oBIN3qPD035989@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jilles
Date: Sat Dec 18 23:03:51 2010
New Revision: 216547
URL: http://svn.freebsd.org/changeset/base/216547

Log:
  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.

Added:
  head/tools/regression/bin/sh/expansion/arith8.0   (contents, props changed)
Modified:
  head/bin/sh/arith_lex.l

Modified: head/bin/sh/arith_lex.l
==============================================================================
--- head/bin/sh/arith_lex.l	Sat Dec 18 23:03:38 2010	(r216546)
+++ head/bin/sh/arith_lex.l	Sat Dec 18 23:03:51 2010	(r216547)
@@ -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;
 		}

Added: head/tools/regression/bin/sh/expansion/arith8.0
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/regression/bin/sh/expansion/arith8.0	Sat Dec 18 23:03:51 2010	(r216547)
@@ -0,0 +1,4 @@
+# $FreeBSD$
+
+v=$( (eval ': $((08))') 2>&1 >/dev/null)
+[ $? -ne 0 ] && [ -n "$v" ]



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201012182303.oBIN3qPD035989>