Module Name: src
Committed By: rillig
Date: Sun Nov 28 09:16:46 UTC 2021
Modified Files:
src/tests/usr.bin/xlint/lint2: t_lint2.sh
src/usr.bin/xlint/lint2: read.c
Log Message:
lint2: in case of parse errors, output the offending line
This provides more of a clue than a simple '(not alnum or _: )',
especially in the output of build.sh.
While here, change the format of the error message to the standard
'%s:%d'. Since these are internal errors, they are not supposed to occur
often, so no need to change error(1).
To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/usr.bin/xlint/lint2/t_lint2.sh
cvs rdiff -u -r1.70 -r1.71 src/usr.bin/xlint/lint2/read.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/tests/usr.bin/xlint/lint2/t_lint2.sh
diff -u src/tests/usr.bin/xlint/lint2/t_lint2.sh:1.9 src/tests/usr.bin/xlint/lint2/t_lint2.sh:1.10
--- src/tests/usr.bin/xlint/lint2/t_lint2.sh:1.9 Sun Nov 28 09:10:36 2021
+++ src/tests/usr.bin/xlint/lint2/t_lint2.sh Sun Nov 28 09:16:46 2021
@@ -1,4 +1,4 @@
-# $NetBSD: t_lint2.sh,v 1.9 2021/11/28 09:10:36 rillig Exp $
+# $NetBSD: t_lint2.sh,v 1.10 2021/11/28 09:16:46 rillig Exp $
#
# Copyright (c) 2021 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -76,6 +76,7 @@ emit_lp64_body()
std_emit_body 'emit_lp64'
}
+# usage: test_error input message-regex [input-regex]
test_error()
{
printf '%s\n' \
@@ -86,7 +87,8 @@ test_error()
"$1" \
> 'input.ln'
- atf_check -s 'exit:1' -e "match:input file error: input\\.ln,3 \($2\)\$" \
+ atf_check -s 'exit:1' \
+ -e "match:error: input\\.ln:3: $2 \\(for '${3-$1}'\\)\$" \
"$lint2" 'input.ln'
}
@@ -141,9 +143,9 @@ error_cases_body()
test_error '0c0.0s2"' 'trailing data: '
test_error '0c0.0s2"%' 'missing closing quote'
# shellcheck disable=SC1003
- test_error '0c0.0s2"\' 'missing after \\'
+ test_error '0c0.0s2"\' 'missing after \\' '0c0\.0s2"\\'
# shellcheck disable=SC1003
- test_error '0c0.0s2"%\' 'missing after \\'
+ test_error '0c0.0s2"%\' 'missing after \\' '0c0\.0s2"%\\'
# declarations and definitions
test_error '0d0' 'bad line number'
@@ -168,6 +170,7 @@ error_cases_body()
test_error '0u0.0' 'bad delim '
test_error '0u0.0_' 'bad delim _'
test_error '0u0.0x' 'not a number: '
+
# trailing garbage is not detected
test_error_ignored '0u0.0x3var_'
}
Index: src/usr.bin/xlint/lint2/read.c
diff -u src/usr.bin/xlint/lint2/read.c:1.70 src/usr.bin/xlint/lint2/read.c:1.71
--- src/usr.bin/xlint/lint2/read.c:1.70 Sun Nov 28 08:21:49 2021
+++ src/usr.bin/xlint/lint2/read.c Sun Nov 28 09:16:46 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: read.c,v 1.70 2021/11/28 08:21:49 rillig Exp $ */
+/* $NetBSD: read.c,v 1.71 2021/11/28 09:16:46 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: read.c,v 1.70 2021/11/28 08:21:49 rillig Exp $");
+__RCSID("$NetBSD: read.c,v 1.71 2021/11/28 09:16:46 rillig Exp $");
#endif
#include <ctype.h>
@@ -90,6 +90,7 @@ static hte_t **renametab;
/* index of current C source file (as specified at the command line) */
static int csrcfile;
+static const char *readfile_line;
static void inperr(const char *, ...)
__attribute__((format(printf, 1, 2), noreturn));
@@ -228,11 +229,13 @@ readfile(const char *name)
err(1, "cannot open %s", name);
while ((line = fgetln(inp, &len)) != NULL) {
+ readfile_line = line;
if (len == 0 || line[len - 1] != '\n')
inperr("%s", &line[len - 1]);
line[len - 1] = '\0';
read_ln_line(line, len);
+ readfile_line = NULL;
}
_destroyhash(renametab);
@@ -254,8 +257,8 @@ inperr(const char *fmt, ...)
(void)vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
- errx(1, "input file error: %s,%zu (%s)",
- fnames[srcfile], flines[srcfile], buf);
+ errx(1, "error: %s:%zu: %s (for '%s')",
+ fnames[srcfile], flines[srcfile], buf, readfile_line);
}
/*