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: always use braces in do-while loops



details:   https://anonhg.NetBSD.org/src/rev/1f2ae78acf61
branches:  trunk
changeset: 960137:1f2ae78acf61
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Mar 08 22:23:58 2021 +0000

description:
indent: always use braces in do-while loops

Having a 'while' at the beginning of a line looks as if it would start a
loop.  It's confusing when it _ends_ a loop instead.

diffstat:

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

diffs (42 lines):

diff -r ec51ea99e04b -r 1f2ae78acf61 usr.bin/indent/io.c
--- a/usr.bin/indent/io.c       Mon Mar 08 22:13:05 2021 +0000
+++ b/usr.bin/indent/io.c       Mon Mar 08 22:23:58 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: io.c,v 1.24 2021/03/07 22:11:01 rillig Exp $   */
+/*     $NetBSD: io.c,v 1.25 2021/03/08 22:23:58 rillig Exp $   */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@
 #include <sys/cdefs.h>
 #ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: io.c,v 1.24 2021/03/07 22:11:01 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.25 2021/03/08 22:23:58 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -126,8 +126,9 @@
                                    || strncmp(s_lab, "#endif", 6) == 0)) {
                char *s = s_lab;
                if (e_lab[-1] == '\n') e_lab--;
-               do putc(*s++, output);
-               while (s < e_lab && 'a' <= *s && *s<='z');
+               do {
+                   putc(*s++, output);
+               } while (s < e_lab && 'a' <= *s && *s <= 'z');
                while ((*s == ' ' || *s == '\t') && s < e_lab)
                    s++;
                if (s < e_lab)
@@ -369,9 +370,9 @@
     }
     if (inhibit_formatting) {
        p = in_buffer;
-       do
+       do {
            putc(*p, output);
-       while (*p++ != '\n');
+       } while (*p++ != '\n');
     }
 }
 



Home | Main Index | Thread Index | Old Index