Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/indent indent: fix parsing of C99 comments containin...



details:   https://anonhg.NetBSD.org/src/rev/8caa1a4c7f3c
branches:  trunk
changeset: 991037:8caa1a4c7f3c
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Nov 04 18:38:37 2021 +0000

description:
indent: fix parsing of C99 comments containing '*/'

diffstat:

 tests/usr.bin/indent/token_comment.c |  13 +++++--------
 usr.bin/indent/pr_comment.c          |   8 ++++----
 2 files changed, 9 insertions(+), 12 deletions(-)

diffs (66 lines):

diff -r 38a5d127ff38 -r 8caa1a4c7f3c tests/usr.bin/indent/token_comment.c
--- a/tests/usr.bin/indent/token_comment.c      Thu Nov 04 18:31:22 2021 +0000
+++ b/tests/usr.bin/indent/token_comment.c      Thu Nov 04 18:38:37 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: token_comment.c,v 1.16 2021/11/04 18:31:22 rillig Exp $ */
+/* $NetBSD: token_comment.c,v 1.17 2021/11/04 18:38:37 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -952,16 +952,13 @@
 
 /*
  * Test for an edge cases in comment handling, having a block comment inside
- * a line comment.
+ * a line comment. Before NetBSD pr_comment.c 1.96 from 2021-11-04, indent
+ * wrongly assumed that the comment would end at the '*' '/', tokenizing the
+ * second word 'still' as a type_at_paren_level_0.
  */
 #indent input
 /* block comment */
 // line comment /* still a line comment */ still a line comment
 #indent end
 
-/* FIXME: The line comment must not be indented. */
-/* FIXME: The '*' '/' in the line comment must not be removed. */
-#indent run
-/* block comment */
- // line comment /* still a line comment  still a line comment
-#indent end
+#indent run-equals-input
diff -r 38a5d127ff38 -r 8caa1a4c7f3c usr.bin/indent/pr_comment.c
--- a/usr.bin/indent/pr_comment.c       Thu Nov 04 18:31:22 2021 +0000
+++ b/usr.bin/indent/pr_comment.c       Thu Nov 04 18:38:37 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pr_comment.c,v 1.95 2021/11/04 17:37:03 rillig Exp $   */
+/*     $NetBSD: pr_comment.c,v 1.96 2021/11/04 18:38:37 rillig Exp $   */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: pr_comment.c,v 1.95 2021/11/04 17:37:03 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.96 2021/11/04 18:38:37 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -270,7 +270,7 @@
 
        case '*':
            inbuf_skip();
-           if (*inp.s == '/') {
+           if (*inp.s == '/' && token.e[-1] == '*') {
        end_of_comment:
                inbuf_skip();
 
@@ -285,7 +285,7 @@
 
                if (!ch_isblank(com.e[-1]) && may_wrap)
                    com_add_char(' ');
-               if (token.e[-1] != '/') {
+               if (token.e[-1] == '*') {
                    com_add_char('*');
                    com_add_char('/');
                }



Home | Main Index | Thread Index | Old Index