Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 9 Jan 2019 09:36:54 +0000 (UTC)
From:      =?UTF-8?Q?Dag-Erling_Sm=c3=b8rgrav?= <des@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r342880 - in head/bin/sh: . tests/expansion
Message-ID:  <201901090936.x099as4S018624@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: des
Date: Wed Jan  9 09:36:54 2019
New Revision: 342880
URL: https://svnweb.freebsd.org/changeset/base/342880

Log:
  Fix an edge case when parsing large numbers which resulted in inconsistent
  results between an expression that refers to a variable by name and the
  same expression that includes the same variable by value.
  
  Submitted by:	se@
  MFC after:	1 week

Added:
  head/bin/sh/tests/expansion/arith15.0   (contents, props changed)
Modified:
  head/bin/sh/shell.h
  head/bin/sh/tests/expansion/Makefile

Modified: head/bin/sh/shell.h
==============================================================================
--- head/bin/sh/shell.h	Wed Jan  9 06:36:57 2019	(r342879)
+++ head/bin/sh/shell.h	Wed Jan  9 09:36:54 2019	(r342880)
@@ -59,8 +59,7 @@
  */
 typedef intmax_t arith_t;
 #define	ARITH_FORMAT_STR  "%" PRIdMAX
-#define	atoarith_t(arg)  strtoimax(arg, NULL, 0)
-#define	strtoarith_t(nptr, endptr, base)  strtoimax(nptr, endptr, base)
+#define	strtoarith_t(nptr, endptr, base)  (intmax_t)strtoumax(nptr, endptr, base)
 #define	ARITH_MIN INTMAX_MIN
 #define	ARITH_MAX INTMAX_MAX
 

Modified: head/bin/sh/tests/expansion/Makefile
==============================================================================
--- head/bin/sh/tests/expansion/Makefile	Wed Jan  9 06:36:57 2019	(r342879)
+++ head/bin/sh/tests/expansion/Makefile	Wed Jan  9 09:36:54 2019	(r342880)
@@ -21,6 +21,7 @@ ${PACKAGE}FILES+=	arith11.0
 ${PACKAGE}FILES+=	arith12.0
 ${PACKAGE}FILES+=	arith13.0
 ${PACKAGE}FILES+=	arith14.0
+${PACKAGE}FILES+=	arith15.0
 ${PACKAGE}FILES+=	assign1.0
 ${PACKAGE}FILES+=	cmdsubst1.0
 ${PACKAGE}FILES+=	cmdsubst2.0

Added: head/bin/sh/tests/expansion/arith15.0
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/bin/sh/tests/expansion/arith15.0	Wed Jan  9 09:36:54 2019	(r342880)
@@ -0,0 +1,20 @@
+# $FreeBSD$
+
+failures=0
+
+check() {
+	if [ $(($1)) != $2 ]; then
+		failures=$((failures+1))
+		echo "For $1, expected $2 actual $(($1))"
+	fi
+}
+
+XXX=-9223372036854775808
+check "XXX"		-9223372036854775808
+check "XXX - 1" 	9223372036854775807
+check $(($XXX - 1))	9223372036854775807
+check $(($XXX - 2))	9223372036854775806
+check $((0x8000000000000000 == 0x7fffffffffffffff)) \
+			0
+
+exit $((failures != 0))



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