Module Name: src
Committed By: rillig
Date: Fri Oct 8 22:37:34 UTC 2021
Modified Files:
src/usr.bin/indent: pr_comment.c
Log Message:
indent: replace unreachable code with assertions
The input buffer is always supposed to be terminated with a newline. The
function inbuf_read_line silently skips null characters. Since the input
buffer is redirected to a temporary buffer in some cases, do not simply
remove this supposed dead code, but replace it with assertions.
In any case, if the code for calling inbuf_read_line had been reachable
and actually allocated a different buffer, continuing to use the pointer
p would have invoked undefined behavior anyway.
To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 src/usr.bin/indent/pr_comment.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/pr_comment.c
diff -u src/usr.bin/indent/pr_comment.c:1.67 src/usr.bin/indent/pr_comment.c:1.68
--- src/usr.bin/indent/pr_comment.c:1.67 Fri Oct 8 22:27:52 2021
+++ src/usr.bin/indent/pr_comment.c Fri Oct 8 22:37:33 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pr_comment.c,v 1.67 2021/10/08 22:27:52 rillig Exp $ */
+/* $NetBSD: pr_comment.c,v 1.68 2021/10/08 22:37:33 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -43,11 +43,12 @@ static char sccsid[] = "@(#)pr_comment.c
#include <sys/cdefs.h>
#if defined(__NetBSD__)
-__RCSID("$NetBSD: pr_comment.c,v 1.67 2021/10/08 22:27:52 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.68 2021/10/08 22:37:33 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $");
#endif
+#include <assert.h>
#include <stdio.h>
#include <string.h>
@@ -169,9 +170,9 @@ process_comment(void)
/* Don't put a break delimiter if this is a one-liner that won't wrap. */
if (break_delim) {
- for (const char *p = inp.s; *p != '\0' && *p != '\n'; p++) {
- if (p >= inp.e)
- inbuf_read_line();
+ for (const char *p = inp.s; *p != '\n'; p++) {
+ assert(*p != '\0');
+ assert(p < inp.e);
if (p[0] == '*' && p[1] == '/') {
/*
* XXX: This computation ignores the leading " * ", as well as