Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/bin/sh Do a better job of reporting invalid numeric constant...
details: https://anonhg.NetBSD.org/src/rev/2a13c4aff23c
branches: trunk
changeset: 358205:2a13c4aff23c
user: kre <kre%NetBSD.org@localhost>
date: Sun Dec 17 04:06:03 2017 +0000
description:
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).
diffstat:
bin/sh/arith_token.c | 12 ++++++++++--
1 files changed, 10 insertions(+), 2 deletions(-)
diffs (33 lines):
diff -r ea19656acb6a -r 2a13c4aff23c bin/sh/arith_token.c
--- a/bin/sh/arith_token.c Sat Dec 16 23:08:40 2017 +0000
+++ b/bin/sh/arith_token.c Sun Dec 17 04:06:03 2017 +0000
@@ -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 @@
* 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));
Home |
Main Index |
Thread Index |
Old Index