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 off-by-one confusion in paren_indent



details:   https://anonhg.NetBSD.org/src/rev/072934fb4060
branches:  trunk
changeset: 1024780:072934fb4060
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Nov 04 17:08:50 2021 +0000

description:
indent: fix off-by-one confusion in paren_indent

The variable was called 'indent' but actually contained a 'column',
which was off by one.

No functional change.

diffstat:

 usr.bin/indent/io.c |  18 ++++++------------
 1 files changed, 6 insertions(+), 12 deletions(-)

diffs (47 lines):

diff -r dca4fa2e4163 -r 072934fb4060 usr.bin/indent/io.c
--- a/usr.bin/indent/io.c       Thu Nov 04 17:07:02 2021 +0000
+++ b/usr.bin/indent/io.c       Thu Nov 04 17:08:50 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: io.c,v 1.111 2021/11/04 17:07:02 rillig Exp $  */
+/*     $NetBSD: io.c,v 1.112 2021/11/04 17:08:50 rillig Exp $  */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: io.c,v 1.111 2021/11/04 17:07:02 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.112 2021/11/04 17:08:50 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -275,7 +275,7 @@
 
     if (ps.paren_level > 0) {
        /* TODO: explain what negative indentation means */
-       paren_indent = -ps.paren_indents[ps.paren_level - 1];
+       paren_indent = -1 - ps.paren_indents[ps.paren_level - 1];
        debug_println("paren_indent is now %d", paren_indent);
     }
 
@@ -306,16 +306,10 @@
     }
 
     if (opt.lineup_to_parens) {
-       if (opt.lineup_to_parens_always) {
-           /*
-            * XXX: where does this '- 1' come from?  It looks strange but is
-            * nevertheless needed for proper indentation, as demonstrated in
-            * the test opt-lpl.0.
-            */
-           return paren_indent - 1;
-       }
+       if (opt.lineup_to_parens_always)
+           return paren_indent;
 
-       int ti = paren_indent - 1;
+       int ti = paren_indent;
        int overflow = ind_add(ti, code.s, code.e) - opt.max_line_length;
        if (overflow < 0)
            return ti;



Home | Main Index | Thread Index | Old Index