Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint1 lint: make parsing of GCC line directive...



details:   https://anonhg.NetBSD.org/src/rev/7a61249886a1
branches:  trunk
changeset: 952875:7a61249886a1
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Feb 20 11:06:56 2021 +0000

description:
lint: make parsing of GCC line directives stricter

The previous code accepted '# 123 "file.c" 23' as specifying a system
header, just because that number ends with '3'.  The original intention
was to compare the complete word, not its suffix.  Fix that.

No practical change since the only flags that are used by GCC are all
single-digit.

diffstat:

 usr.bin/xlint/lint1/lex.c |  19 +++++++++++--------
 1 files changed, 11 insertions(+), 8 deletions(-)

diffs (42 lines):

diff -r ad6eb600dc05 -r 7a61249886a1 usr.bin/xlint/lint1/lex.c
--- a/usr.bin/xlint/lint1/lex.c Sat Feb 20 10:12:52 2021 +0000
+++ b/usr.bin/xlint/lint1/lex.c Sat Feb 20 11:06:56 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.7 2021/01/24 09:44:35 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.8 2021/02/20 11:06:56 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: lex.c,v 1.7 2021/01/24 09:44:35 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.8 2021/02/20 11:06:56 rillig Exp $");
 #endif
 
 #include <ctype.h>
@@ -1031,14 +1031,17 @@
 
        in_system_header = false;
 
-       while (ch_isspace(*p))
-               p++;
-       while (ch_isdigit(*p)) {
-               if (*p == '3' && !ch_isdigit(p[1]))
-                       in_system_header = true;
-               p++;
+       while (*p != '\0') {
                while (ch_isspace(*p))
                        p++;
+
+               const char *word_start = p;
+               while (*p != '\0' && !ch_isspace(*p))
+                       p++;
+               const char *word_end = p;
+
+               if (word_end - word_start == 1 && word_start[0] == '3')
+                       in_system_header = true;
        }
 
 #if 0



Home | Main Index | Thread Index | Old Index