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: only access buffer data in the range ...
details: https://anonhg.NetBSD.org/src/rev/cf165df42267
branches: trunk
changeset: 1024842:cf165df42267
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Nov 07 13:30:15 2021 +0000
description:
indent: only access buffer data in the range [buf.s, buf.e)
No functional change.
diffstat:
tests/usr.bin/indent/opt_cdb.c | 38 +++++++++++++++++++++++++++++++++++++-
usr.bin/indent/indent.c | 10 +++++-----
usr.bin/indent/pr_comment.c | 8 ++++----
3 files changed, 46 insertions(+), 10 deletions(-)
diffs (130 lines):
diff -r e3fd070d721d -r cf165df42267 tests/usr.bin/indent/opt_cdb.c
--- a/tests/usr.bin/indent/opt_cdb.c Sun Nov 07 12:29:58 2021 +0000
+++ b/tests/usr.bin/indent/opt_cdb.c Sun Nov 07 13:30:15 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_cdb.c,v 1.4 2021/10/18 07:11:31 rillig Exp $ */
+/* $NetBSD: opt_cdb.c,v 1.5 2021/11/07 13:30:15 rillig Exp $ */
/* $FreeBSD$ */
/*
@@ -131,3 +131,39 @@
int lc;
}
#indent end
+
+
+#indent input
+/*
+
+ */
+#indent end
+
+#indent run -cdb
+/*
+ *
+ */
+#indent end
+
+#indent run -ncdb
+/*
+ * */
+#indent end
+
+
+#indent input
+/*
+
+*/
+#indent end
+
+#indent run -cdb
+/*
+ *
+ */
+#indent end
+
+#indent run -ncdb
+/*
+ * */
+#indent end
diff -r e3fd070d721d -r cf165df42267 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c Sun Nov 07 12:29:58 2021 +0000
+++ b/usr.bin/indent/indent.c Sun Nov 07 13:30:15 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.c,v 1.212 2021/11/07 07:44:59 rillig Exp $ */
+/* $NetBSD: indent.c,v 1.213 2021/11/07 13:30:15 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
#include <sys/cdefs.h>
#if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.212 2021/11/07 07:44:59 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.213 2021/11/07 13:30:15 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
#endif
@@ -840,7 +840,7 @@
if (ps.want_blank)
return true;
if (token.s[0] == '+' || token.s[0] == '-')
- return code.e[-1] == token.s[0];
+ return code.e > code.s && code.e[-1] == token.s[0];
return false;
}
@@ -1105,7 +1105,7 @@
{
ps.in_stmt = false;
- if (code.e != code.s && (!opt.cuddle_else || code.e[-1] != '}')) {
+ if (code.e > code.s && (!opt.cuddle_else || code.e[-1] != '}')) {
if (opt.verbose)
diag(0, "Line broken");
dump_line(); /* make sure this starts a line */
@@ -1199,7 +1199,7 @@
static void
process_period(void)
{
- if (code.e[-1] == ',')
+ if (code.e > code.s && code.e[-1] == ',')
*code.e++ = ' ';
*code.e++ = '.';
ps.want_blank = false;
diff -r e3fd070d721d -r cf165df42267 usr.bin/indent/pr_comment.c
--- a/usr.bin/indent/pr_comment.c Sun Nov 07 12:29:58 2021 +0000
+++ b/usr.bin/indent/pr_comment.c Sun Nov 07 13:30:15 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pr_comment.c,v 1.113 2021/11/07 12:29:58 rillig Exp $ */
+/* $NetBSD: pr_comment.c,v 1.114 2021/11/07 13:30:15 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.113 2021/11/07 12:29:58 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.114 2021/11/07 13:30:15 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $");
#endif
@@ -239,7 +239,7 @@
} else {
ps.next_col_1 = true;
- if (!ch_isblank(com.e[-1]))
+ if (!(com.e > com.s && ch_isblank(com.e[-1])))
com_add_char(' ');
last_blank = com.e - 1 - com.buf;
}
@@ -273,7 +273,7 @@
com_add_char(' ');
}
- if (!ch_isblank(com.e[-1]))
+ if (!(com.e > com.s && ch_isblank(com.e[-1])))
com_add_char(' ');
com_add_char('*');
com_add_char('/');
Home |
Main Index |
Thread Index |
Old Index