Module Name: src
Committed By: rillig
Date: Fri Oct 29 20:05:58 UTC 2021
Modified Files:
src/tests/usr.bin/indent: t_errors.sh
src/usr.bin/indent: indent.c
Log Message:
indent: replace segmentation fault with assertion
To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/tests/usr.bin/indent/t_errors.sh
cvs rdiff -u -r1.175 -r1.176 src/usr.bin/indent/indent.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/tests/usr.bin/indent/t_errors.sh
diff -u src/tests/usr.bin/indent/t_errors.sh:1.12 src/tests/usr.bin/indent/t_errors.sh:1.13
--- src/tests/usr.bin/indent/t_errors.sh:1.12 Fri Oct 29 19:39:32 2021
+++ src/tests/usr.bin/indent/t_errors.sh Fri Oct 29 20:05:58 2021
@@ -1,5 +1,5 @@
#! /bin/sh
-# $NetBSD: t_errors.sh,v 1.12 2021/10/29 19:39:32 rillig Exp $
+# $NetBSD: t_errors.sh,v 1.13 2021/10/29 20:05:58 rillig Exp $
#
# Copyright (c) 2021 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -413,7 +413,7 @@ search_stmt_comment_segv_body()
{
printf '{if(expr\n)/*c*/;}\n' > code.c
- atf_check -s 'signal' \
+ atf_check -s 'signal' -o 'ignore' -e 'match:assert' \
"$indent" code.c -st
}
Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.175 src/usr.bin/indent/indent.c:1.176
--- src/usr.bin/indent/indent.c:1.175 Fri Oct 29 19:31:24 2021
+++ src/usr.bin/indent/indent.c Fri Oct 29 20:05:58 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.c,v 1.175 2021/10/29 19:31:24 rillig Exp $ */
+/* $NetBSD: indent.c,v 1.176 2021/10/29 20:05:58 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c 5.1
#include <sys/cdefs.h>
#if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.175 2021/10/29 19:31:24 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.176 2021/10/29 20:05:58 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
#endif
@@ -53,6 +53,7 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/
#include <sys/capsicum.h>
#include <capsicum_helpers.h>
#endif
+#include <assert.h>
#include <ctype.h>
#include <err.h>
#include <errno.h>
@@ -194,6 +195,7 @@ search_stmt_comment(bool *comment_buffer
* is an additional line break before the ')', memcpy tries to copy
* (size_t)-1 bytes.
*/
+ assert((size_t)(inp.s - inp.buf) >= 4);
memcpy(sc_buf, inp.buf, (size_t)(inp.s - inp.buf) - 4);
save_com = sc_buf + (inp.s - inp.buf - 4);
save_com[0] = save_com[1] = ' ';