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 assertion in fits_in_one_line



details:   https://anonhg.NetBSD.org/src/rev/6fdd977e953f
branches:  trunk
changeset: 990583:6fdd977e953f
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Oct 30 16:57:18 2021 +0000

description:
indent: fix assertion in fits_in_one_line

diffstat:

 tests/usr.bin/indent/t_errors.sh     |  19 ++++++++++++++++-
 tests/usr.bin/indent/token_comment.c |  37 +++++++++++++++++++++++++++++++++++-
 usr.bin/indent/pr_comment.c          |   7 ++---
 3 files changed, 56 insertions(+), 7 deletions(-)

diffs (117 lines):

diff -r 50acec1626a2 -r 6fdd977e953f tests/usr.bin/indent/t_errors.sh
--- a/tests/usr.bin/indent/t_errors.sh  Sat Oct 30 16:43:23 2021 +0000
+++ b/tests/usr.bin/indent/t_errors.sh  Sat Oct 30 16:57:18 2021 +0000
@@ -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 @@
        # 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 @@
 }
 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
 }
 
diff -r 50acec1626a2 -r 6fdd977e953f tests/usr.bin/indent/token_comment.c
--- a/tests/usr.bin/indent/token_comment.c      Sat Oct 30 16:43:23 2021 +0000
+++ b/tests/usr.bin/indent/token_comment.c      Sat Oct 30 16:57:18 2021 +0000
@@ -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 @@
  * Ü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
diff -r 50acec1626a2 -r 6fdd977e953f usr.bin/indent/pr_comment.c
--- a/usr.bin/indent/pr_comment.c       Sat Oct 30 16:43:23 2021 +0000
+++ b/usr.bin/indent/pr_comment.c       Sat Oct 30 16:57:18 2021 +0000
@@ -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 @@
 
 #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 @@
 
        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;
 }



Home | Main Index | Thread Index | Old Index