Module Name:    src
Committed By:   rillig
Date:           Mon May 30 15:13:25 UTC 2022

Modified Files:
        src/usr.bin/xlint/lint1: main1.c

Log Message:
lint: report proper file name in assertion failures

When given the (obviously malformed) translation unit 'f=({;};}', lint
runs into an assertion failure.  It reported this as occurring near
':1'.  This location was missing a filename since the input didn't
contain a GCC line number directive such as '# 2 "input.c"'.  In GCC mode,
the GCC builtins are loaded first, in which case the reported location
was ':9'.

Fix this by providing proper location information, even for input that
does not come from the GCC C preprocessor.


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/usr.bin/xlint/lint1/main1.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/xlint/lint1/main1.c
diff -u src/usr.bin/xlint/lint1/main1.c:1.62 src/usr.bin/xlint/lint1/main1.c:1.63
--- src/usr.bin/xlint/lint1/main1.c:1.62	Fri May 20 21:18:55 2022
+++ src/usr.bin/xlint/lint1/main1.c	Mon May 30 15:13:25 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: main1.c,v 1.62 2022/05/20 21:18:55 rillig Exp $	*/
+/*	$NetBSD: main1.c,v 1.63 2022/05/30 15:13:25 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: main1.c,v 1.62 2022/05/20 21:18:55 rillig Exp $");
+__RCSID("$NetBSD: main1.c,v 1.63 2022/05/30 15:13:25 rillig Exp $");
 #endif
 
 #include <sys/types.h>
@@ -288,6 +288,9 @@ main(int argc, char *argv[])
 	if (allow_gcc && allow_c90) {
 		if ((yyin = gcc_builtins()) == NULL)
 			err(1, "cannot open builtins");
+		curr_pos.p_file = "<gcc-builtins>";
+		curr_pos.p_line = 0;
+		lex_next_line();
 		yyparse();
 		(void)fclose(yyin);
 	}
@@ -295,6 +298,9 @@ main(int argc, char *argv[])
 	/* open the input file */
 	if ((yyin = fopen(argv[0], "r")) == NULL)
 		err(1, "cannot open '%s'", argv[0]);
+	curr_pos.p_file = argv[0];
+	curr_pos.p_line = 0;
+	lex_next_line();
 	yyparse();
 	(void)fclose(yyin);
 

Reply via email to