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: fix error message for buffer overflow...



details:   https://anonhg.NetBSD.org/src/rev/9dbdeb5ee3d7
branches:  trunk
changeset: 990485:9dbdeb5ee3d7
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Oct 28 21:35:57 2021 +0000

description:
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.

diffstat:

 tests/usr.bin/indent/t_errors.sh |  5 ++---
 usr.bin/indent/args.c            |  7 +++----
 2 files changed, 5 insertions(+), 7 deletions(-)

diffs (50 lines):

diff -r 41bf675ff110 -r 9dbdeb5ee3d7 tests/usr.bin/indent/t_errors.sh
--- a/tests/usr.bin/indent/t_errors.sh  Thu Oct 28 21:32:48 2021 +0000
+++ b/tests/usr.bin/indent/t_errors.sh  Thu Oct 28 21:35:57 2021 +0000
@@ -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 @@
        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
 }
 
diff -r 41bf675ff110 -r 9dbdeb5ee3d7 usr.bin/indent/args.c
--- a/usr.bin/indent/args.c     Thu Oct 28 21:32:48 2021 +0000
+++ b/usr.bin/indent/args.c     Thu Oct 28 21:35:57 2021 +0000
@@ -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 @@
 
 #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 @@
            } 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;
        }



Home | Main Index | Thread Index | Old Index