Module Name: src
Committed By: kre
Date: Sun Dec 17 04:06:03 UTC 2017
Modified Files:
src/bin/sh: arith_token.c
Log Message:
Do a better job of reporting invalid numeric constants in arithmetic exprs.
For example, given $(( 08 + 1 )) (or similar) instead of reporting
"expecting end of expression" - the generic error for parse failed,
which happened as this was parsed as $(( 0 8 + 1 )) because the 8
could not be a part of an octal constant, and that expr makes no sense -
instead say "unexpected '8' (out of range) in numeric constant: 08"
which makes the cause of the error more obvious.
NFC for valid expressions, just the error message (and the way the
error is detected).
To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/bin/sh/arith_token.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/bin/sh/arith_token.c
diff -u src/bin/sh/arith_token.c:1.6 src/bin/sh/arith_token.c:1.7
--- src/bin/sh/arith_token.c:1.6 Mon Jul 24 13:21:14 2017
+++ src/bin/sh/arith_token.c Sun Dec 17 04:06:03 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: arith_token.c,v 1.6 2017/07/24 13:21:14 kre Exp $ */
+/* $NetBSD: arith_token.c,v 1.7 2017/12/17 04:06:03 kre Exp $ */
/*-
* Copyright (c) 2002
@@ -39,7 +39,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: arith_token.c,v 1.6 2017/07/24 13:21:14 kre Exp $");
+__RCSID("$NetBSD: arith_token.c,v 1.7 2017/12/17 04:06:03 kre Exp $");
#endif /* not lint */
#include <inttypes.h>
@@ -87,6 +87,14 @@ arith_token(void)
* strtoimax() stops...
*/
a_t_val.val = strtoimax(buf, &end, 0);
+ if (is_in_name(*end)) {
+ token = *end;
+ while (is_in_name(*++end))
+ continue;
+ error("arithmetic: unexpected '%c' "
+ "(out of range) in numeric constant: "
+ "%.*s", token, (int)(end - buf), buf);
+ }
arith_buf = end;
VTRACE(DBG_ARITH, ("Arith token ARITH_NUM=%jd\n",
a_t_val.val));