Module Name: src
Committed By: rillig
Date: Sat Oct 30 16:57:18 UTC 2021
Modified Files:
src/tests/usr.bin/indent: t_errors.sh token_comment.c
src/usr.bin/indent: pr_comment.c
Log Message:
indent: fix assertion in fits_in_one_line
To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/tests/usr.bin/indent/t_errors.sh
cvs rdiff -u -r1.13 -r1.14 src/tests/usr.bin/indent/token_comment.c
cvs rdiff -u -r1.90 -r1.91 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/t_errors.sh
diff -u src/tests/usr.bin/indent/t_errors.sh:1.16 src/tests/usr.bin/indent/t_errors.sh:1.17
--- src/tests/usr.bin/indent/t_errors.sh:1.16 Sat Oct 30 16:43:23 2021
+++ src/tests/usr.bin/indent/t_errors.sh Sat Oct 30 16:57:18 2021
@@ -1,5 +1,5 @@
#! /bin/sh
-# $NetBSD: t_errors.sh,v 1.16 2021/10/30 16:43:23 rillig Exp $
+# $NetBSD: t_errors.sh,v 1.17 2021/10/30 16:57:18 rillig Exp $
#
# Copyright (c) 2021 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -435,6 +435,8 @@ search_stmt_fits_in_one_line_body()
# The comment is placed after 'if (0) ...', where it is processed
# by search_stmt_comment. That function redirects the input buffer to
# a temporary buffer that is not guaranteed to be terminated by '\n'.
+ # Before NetBSD pr_comment.c 1.91 from 2021-10-30, this produced an
+ # assertion failure in fits_in_one_line.
cat <<EOF > code.c
int f(void)
{
@@ -443,7 +445,20 @@ int f(void)
}
EOF
- atf_check -s 'signal' -o 'ignore' -e 'match:assert' \
+ # Indent tries hard to make the comment fit to the 34-character line
+ # length, but it is just not possible.
+ cat <<EOF > expected.out
+int
+f(void)
+{
+ if (0)
+ /*
+ * 0123456789012345678901
+ */ ;
+}
+EOF
+
+ atf_check -o 'file:expected.out' \
"$indent" -l34 code.c -st
}
Index: src/tests/usr.bin/indent/token_comment.c
diff -u src/tests/usr.bin/indent/token_comment.c:1.13 src/tests/usr.bin/indent/token_comment.c:1.14
--- src/tests/usr.bin/indent/token_comment.c:1.13 Sat Oct 30 15:26:58 2021
+++ src/tests/usr.bin/indent/token_comment.c Sat Oct 30 16:57:18 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: token_comment.c,v 1.13 2021/10/30 15:26:58 rillig Exp $ */
+/* $NetBSD: token_comment.c,v 1.14 2021/10/30 16:57:18 rillig Exp $ */
/* $FreeBSD$ */
/*
@@ -913,3 +913,38 @@ end */
* Ümläute
*/
#indent end
+
+
+/*
+ *
+ */
+#indent input
+int f(void)
+{
+ if (0)
+ /* 12 1234 123 123456 1234 1234567 123 1234. */;
+}
+#indent end
+
+/* The comment is too long to fit in a single line. */
+#indent run -l54
+int
+f(void)
+{
+ if (0)
+ /*
+ * 12 1234 123 123456 1234 1234567 123
+ * 1234.
+ */ ;
+}
+#indent end
+
+/* The comment fits in a single line. */
+#indent run
+int
+f(void)
+{
+ if (0)
+ /* 12 1234 123 123456 1234 1234567 123 1234. */ ;
+}
+#indent end
Index: src/usr.bin/indent/pr_comment.c
diff -u src/usr.bin/indent/pr_comment.c:1.90 src/usr.bin/indent/pr_comment.c:1.91
--- src/usr.bin/indent/pr_comment.c:1.90 Fri Oct 29 20:27:42 2021
+++ src/usr.bin/indent/pr_comment.c Sat Oct 30 16:57:18 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pr_comment.c,v 1.90 2021/10/29 20:27:42 rillig Exp $ */
+/* $NetBSD: pr_comment.c,v 1.91 2021/10/30 16:57:18 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.90 2021/10/29 20:27:42 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.91 2021/10/30 16:57:18 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $");
#endif
@@ -94,8 +94,7 @@ fits_in_one_line(int max_line_length)
int len = indentation_after_range(ps.com_ind + 3, inp.s, p);
len += ch_isblank(p[-1]) ? 2 : 3;
- if (len <= max_line_length)
- return true;
+ return len <= max_line_length;
}
return false;
}