Module Name:    src
Committed By:   rillig
Date:           Sun Jun  4 14:38:16 UTC 2023

Modified Files:
        src/usr.bin/indent: indent.c io.c

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

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.324 -r1.325 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.189 -r1.190 src/usr.bin/indent/io.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.324 src/usr.bin/indent/indent.c:1.325
--- src/usr.bin/indent/indent.c:1.324	Sun Jun  4 14:20:00 2023
+++ src/usr.bin/indent/indent.c	Sun Jun  4 14:38:15 2023
@@ -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 ||

Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.189 src/usr.bin/indent/io.c:1.190
--- src/usr.bin/indent/io.c:1.189	Sun Jun  4 13:49:00 2023
+++ src/usr.bin/indent/io.c	Sun Jun  4 14:38:15 2023
@@ -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;

Reply via email to