Module Name:    src
Committed By:   rillig
Date:           Thu Nov  4 18:38:37 UTC 2021

Modified Files:
        src/tests/usr.bin/indent: token_comment.c
        src/usr.bin/indent: pr_comment.c

Log Message:
indent: fix parsing of C99 comments containing '*/'


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/tests/usr.bin/indent/token_comment.c
cvs rdiff -u -r1.95 -r1.96 src/usr.bin/indent/pr_comment.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/indent/token_comment.c
diff -u src/tests/usr.bin/indent/token_comment.c:1.16 src/tests/usr.bin/indent/token_comment.c:1.17
--- src/tests/usr.bin/indent/token_comment.c:1.16	Thu Nov  4 18:31:22 2021
+++ src/tests/usr.bin/indent/token_comment.c	Thu Nov  4 18:38:37 2021
@@ -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 @@ f(void)
 
 /*
  * 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

Index: src/usr.bin/indent/pr_comment.c
diff -u src/usr.bin/indent/pr_comment.c:1.95 src/usr.bin/indent/pr_comment.c:1.96
--- src/usr.bin/indent/pr_comment.c:1.95	Thu Nov  4 17:37:03 2021
+++ src/usr.bin/indent/pr_comment.c	Thu Nov  4 18:38:37 2021
@@ -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 @@ static char sccsid[] = "@(#)pr_comment.c
 
 #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 @@ copy_comment(int adj_max_line_length, bo
 
 	case '*':
 	    inbuf_skip();
-	    if (*inp.s == '/') {
+	    if (*inp.s == '/' && token.e[-1] == '*') {
 	end_of_comment:
 		inbuf_skip();
 
@@ -285,7 +285,7 @@ copy_comment(int adj_max_line_length, bo
 
 		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('/');
 		}

Reply via email to