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 scanning of no-wrap comments (sin...



details:   https://anonhg.NetBSD.org/src/rev/935b1cfb1a69
branches:  trunk
changeset: 376599:935b1cfb1a69
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Jun 23 20:59:04 2023 +0000

description:
indent: fix scanning of no-wrap comments (since 2021.11.07.10.34.03)

The "refactoring" back then tried to be too clever.

diffstat:

 tests/usr.bin/indent/lsym_comment.c |   8 +++-----
 usr.bin/indent/pr_comment.c         |  15 ++++++++-------
 2 files changed, 11 insertions(+), 12 deletions(-)

diffs (66 lines):

diff -r c7a3c63bd368 -r 935b1cfb1a69 tests/usr.bin/indent/lsym_comment.c
--- a/tests/usr.bin/indent/lsym_comment.c       Fri Jun 23 20:44:51 2023 +0000
+++ b/tests/usr.bin/indent/lsym_comment.c       Fri Jun 23 20:59:04 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_comment.c,v 1.23 2023/06/18 07:10:24 rillig Exp $ */
+/* $NetBSD: lsym_comment.c,v 1.24 2023/06/23 20:59:04 rillig Exp $ */
 
 /*
  * Tests for the token lsym_comment, which starts a comment.
@@ -1131,6 +1131,7 @@ int block;                        /* comment line 1 comment l
 //indent end
 
 
+// Ensure that '/*/' is not interpreted as a complete comment.
 //indent input
 /*/ comment? or:not; /* */
 //indent end
@@ -1139,10 +1140,7 @@ int block;                       /* comment line 1 comment l
 /* / comment? or:not; /* */
 //indent end
 
-//indent run -nfc1
-// $ FIXME: It's a comment, not code.
-/*/ comment ? or : not;                /* */
-//indent end
+//indent run-equals-input -nfc1
 
 
 /*
diff -r c7a3c63bd368 -r 935b1cfb1a69 usr.bin/indent/pr_comment.c
--- a/usr.bin/indent/pr_comment.c       Fri Jun 23 20:44:51 2023 +0000
+++ b/usr.bin/indent/pr_comment.c       Fri Jun 23 20:59:04 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pr_comment.c,v 1.170 2023/06/18 07:32:33 rillig Exp $  */
+/*     $NetBSD: pr_comment.c,v 1.171 2023/06/23 20:59:04 rillig Exp $  */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: pr_comment.c,v 1.170 2023/06/18 07:32:33 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.171 2023/06/23 20:59:04 rillig Exp $");
 
 #include <string.h>
 
@@ -325,12 +325,13 @@ copy_comment_nowrap(void)
                        continue;
                }
 
+               if (kind == '*' && inp_p[0] == '*' && inp_p[1] == '/') {
+                       com_add_char(*inp_p++);
+                       com_add_char(*inp_p++);
+                       return;
+               }
+
                com_add_char(*inp_p++);
-               if (com.len >= 2
-                   && com.s[com.len - 2] == '*'
-                   && com.s[com.len - 1] == '/'
-                   && kind == '*')
-                       return;
        }
 }
 



Home | Main Index | Thread Index | Old Index