Module Name:    src
Committed By:   rillig
Date:           Thu Nov 25 20:14:00 UTC 2021

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

Log Message:
tests/indent: demonstrate bugs in comment processing


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/tests/usr.bin/indent/token_comment.c
cvs rdiff -u -r1.121 -r1.122 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.24 src/tests/usr.bin/indent/token_comment.c:1.25
--- src/tests/usr.bin/indent/token_comment.c:1.24	Sat Nov 20 16:54:17 2021
+++ src/tests/usr.bin/indent/token_comment.c	Thu Nov 25 20:14:00 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: token_comment.c,v 1.24 2021/11/20 16:54:17 rillig Exp $ */
+/* $NetBSD: token_comment.c,v 1.25 2021/11/25 20:14:00 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -1049,3 +1049,37 @@ line 4
 #indent end
 
 #indent run-equals-input
+
+
+/*
+ * The function analyze_comment wrongly joins the two comments.
+ */
+#indent input
+/*
+ *//*
+join*/
+#indent end
+
+#indent run -nfc1
+/*
+  *
+  * join
+  */
+#indent end
+
+
+/*
+ * The function analyze_comment generates malformed output.
+ */
+#indent input
+/*
+*//*
+error*/
+#indent end
+
+#indent run -nfc1
+/*
+ */
+  * error
+  */
+#indent end

Index: src/usr.bin/indent/pr_comment.c
diff -u src/usr.bin/indent/pr_comment.c:1.121 src/usr.bin/indent/pr_comment.c:1.122
--- src/usr.bin/indent/pr_comment.c:1.121	Fri Nov 19 20:23:17 2021
+++ src/usr.bin/indent/pr_comment.c	Thu Nov 25 20:14:00 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pr_comment.c,v 1.121 2021/11/19 20:23:17 rillig Exp $	*/
+/*	$NetBSD: pr_comment.c,v 1.122 2021/11/25 20:14:00 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.121 2021/11/19 20:23:17 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.122 2021/11/25 20:14:00 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -123,6 +123,12 @@ analyze_comment(bool *p_may_wrap, bool *
 	    break_delim = false;
 	}
 
+	/*
+	 * XXX: This condition looks suspicious since it ignores the case
+	 * where the end of the previous comment is still in 'com'.
+	 *
+	 * See test token_comment.c, keyword 'analyze_comment'.
+	 */
 	if (lab.s == lab.e && code.s == code.e) {
 	    adj_max_line_length = opt.block_comment_max_line_length;
 	    com_ind = (ps.ind_level - opt.unindent_displace) * opt.indent_size;
@@ -172,6 +178,12 @@ analyze_comment(bool *p_may_wrap, bool *
 	break_delim = false;
 
     if (break_delim) {
+	/*
+	 * FIXME: This code wrongly joins comments in '-nfc1' mode and
+	 * generates malformed code.
+	 *
+	 * See test token_comment.c, keyword 'analyze_comment'.
+	 */
 	com.e = com.s + 2;
 	*com.e = '\0';
 	if (opt.blanklines_before_block_comments &&

Reply via email to