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: ensure that the 'block init level' ne...



details:   https://anonhg.NetBSD.org/src/rev/4741ab07618a
branches:  trunk
changeset: 376200:4741ab07618a
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jun 04 14:38:15 2023 +0000

description:
indent: ensure that the 'block init level' never goes negative

No functional change.

diffstat:

 usr.bin/indent/indent.c |  11 +++++------
 usr.bin/indent/io.c     |   6 +++---
 2 files changed, 8 insertions(+), 9 deletions(-)

diffs (73 lines):

diff -r c63078a4c089 -r 4741ab07618a usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Sun Jun 04 14:20:00 2023 +0000
+++ b/usr.bin/indent/indent.c   Sun Jun 04 14:38:15 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.324 2023/06/04 14:20:00 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.325 2023/06/04 14:38:15 rillig Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.324 2023/06/04 14:20:00 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.325 2023/06/04 14:38:15 rillig Exp $");
 
 #include <sys/param.h>
 #include <err.h>
@@ -782,8 +782,6 @@ process_lbrace(void)
 
        if (!ps.block_init)
                ps.force_nl = true;
-       else if (ps.block_init_level <= 0)
-               ps.block_init_level = 1;
        else
                ps.block_init_level++;
 
@@ -848,7 +846,8 @@ process_rbrace(void)
        }
 
        ps.declaration = decl_no;
-       ps.block_init_level--;
+       if (ps.block_init_level > 0)
+               ps.block_init_level--;
 
        if (code.len > 0 && !ps.block_init) {
                if (opt.verbose)
@@ -999,7 +998,7 @@ process_comma(void)
        buf_add_char(&code, ',');
 
        if (ps.nparen == 0) {
-               if (ps.block_init_level <= 0)
+               if (ps.block_init_level == 0)
                        ps.block_init = false;
                int typical_varname_length = 8;
                if (ps.break_after_comma && (opt.break_after_comma ||
diff -r c63078a4c089 -r 4741ab07618a usr.bin/indent/io.c
--- a/usr.bin/indent/io.c       Sun Jun 04 14:20:00 2023 +0000
+++ b/usr.bin/indent/io.c       Sun Jun 04 14:38:15 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: io.c,v 1.189 2023/06/04 13:49:00 rillig Exp $  */
+/*     $NetBSD: io.c,v 1.190 2023/06/04 14:38:15 rillig Exp $  */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: io.c,v 1.189 2023/06/04 13:49:00 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.190 2023/06/04 14:38:15 rillig Exp $");
 
 #include <stdio.h>
 
@@ -301,7 +301,7 @@ output_line(void)
 dont_write_line:
        ps.decl_on_line = ps.in_decl;   /* for proper comment indentation */
        ps.in_stmt_cont = ps.in_stmt_or_decl
-           && !ps.in_decl && ps.block_init_level <= 0;
+           && !ps.in_decl && ps.block_init_level == 0;
        ps.decl_indent_done = false;
        if (ps.extra_expr_indent == eei_last)
                ps.extra_expr_indent = eei_no;



Home | Main Index | Thread Index | Old Index