Module Name:    src
Committed By:   rillig
Date:           Thu Oct 28 21:35:57 UTC 2021

Modified Files:
        src/tests/usr.bin/indent: t_errors.sh
        src/usr.bin/indent: args.c

Log Message:
indent: fix error message for buffer overflow during option parsing

At this early time, the input file has not been opened yet, so there is
no reason to output either the input file name or the line number.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/indent/t_errors.sh
cvs rdiff -u -r1.64 -r1.65 src/usr.bin/indent/args.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.7 src/tests/usr.bin/indent/t_errors.sh:1.8
--- src/tests/usr.bin/indent/t_errors.sh:1.7	Thu Oct 28 21:32:49 2021
+++ src/tests/usr.bin/indent/t_errors.sh	Thu Oct 28 21:35:57 2021
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $NetBSD: t_errors.sh,v 1.7 2021/10/28 21:32:49 rillig Exp $
+# $NetBSD: t_errors.sh,v 1.8 2021/10/28 21:35:57 rillig Exp $
 #
 # Copyright (c) 2021 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -152,9 +152,8 @@ option_buffer_overflow_body()
 	opt="$opt$opt$opt$opt$opt$opt$opt$opt"	# 16384
 	printf '%s\n' "-$opt" > indent.pro
 
-	# TODO: The call to 'diag' should be replaced with 'errx'.
 	expect_error \
-	    'error: Standard Input:1: buffer overflow in indent.pro, starting with '\''-123456781'\''' \
+	    'indent: buffer overflow in indent.pro, starting with '\''-123456781'\''' \
 	    -Pindent.pro
 }
 

Index: src/usr.bin/indent/args.c
diff -u src/usr.bin/indent/args.c:1.64 src/usr.bin/indent/args.c:1.65
--- src/usr.bin/indent/args.c:1.64	Thu Oct 28 21:32:48 2021
+++ src/usr.bin/indent/args.c	Thu Oct 28 21:35:57 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: args.c,v 1.64 2021/10/28 21:32:48 rillig Exp $	*/
+/*	$NetBSD: args.c,v 1.65 2021/10/28 21:35:57 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)args.c	8.1 (
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: args.c,v 1.64 2021/10/28 21:32:48 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.65 2021/10/28 21:35:57 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
 #endif
@@ -282,9 +282,8 @@ load_profile(const char *fname, bool mus
 	    } else if (isspace((unsigned char)ch)) {
 		break;
 	    } else if (n >= array_length(buf) - 5) {
-		diag(1, "buffer overflow in %s, starting with '%.10s'",
+		errx(1, "buffer overflow in %s, starting with '%.10s'",
 		     fname, buf);
-		exit(1);
 	    } else
 		buf[n++] = (char)ch;
 	}

Reply via email to