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: remove code that accessed out-of-boun...



details:   https://anonhg.NetBSD.org/src/rev/9c3f37e5dc3f
branches:  trunk
changeset: 1024843:9c3f37e5dc3f
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Nov 07 13:38:32 2021 +0000

description:
indent: remove code that accessed out-of-bounds data from buffer

Saving and restoring the exact buffer position had been necessary before
NetBSD pr_comment.c 1.114. The code accessed the buffer data out of the
bounds of [com.s, com.e), which was rather surprising. More
specifically, it accessed com.e[-1] in a case where com.e == com.s,
relying on com.e[-1] being ' ' in most cases and '*' in the case where
the comment delimiter was written to a separate output line.

Make the code easier understandable by only ever accessing the buffer
data in the bounds [buf.s, buf.e).

No functional change.

diffstat:

 usr.bin/indent/pr_comment.c |  6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)

diffs (33 lines):

diff -r cf165df42267 -r 9c3f37e5dc3f usr.bin/indent/pr_comment.c
--- a/usr.bin/indent/pr_comment.c       Sun Nov 07 13:30:15 2021 +0000
+++ b/usr.bin/indent/pr_comment.c       Sun Nov 07 13:38:32 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pr_comment.c,v 1.114 2021/11/07 13:30:15 rillig Exp $  */
+/*     $NetBSD: pr_comment.c,v 1.115 2021/11/07 13:38:32 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.114 2021/11/07 13:30:15 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.115 2021/11/07 13:38:32 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -181,14 +181,12 @@
        break_delim = false;
 
     if (break_delim) {
-       char *t = com.e;
        com.e = com.s + 2;
        *com.e = '\0';
        if (opt.blanklines_before_block_comments &&
                ps.prev_token != lsym_lbrace)
            blank_line_before = true;
        dump_line();
-       com.e = com.s = t;
        com_add_delim();
     }
 



Home | Main Index | Thread Index | Old Index