>From 8021dd7c70f958fa42f971422ab2c9a61c4ea0a9 Mon Sep 17 00:00:00 2001 From: Assaf Gordon Date: Wed, 19 Dec 2018 01:02:32 -0700 Subject: [PATCH] base64: fix 'extra operand' error message In the following invocation, 'a' is the input file, and 'b' is the extra operand: $ base64 a b Report 'b' in the error message instead of 'a': $ base64 a b base64: extra operand 'b' * src/base64.c (main): If there is more than one non-option operand, report the second one (assuming the first is a the input file name). * tests/misc/base64.pl: Add tests. --- src/base64.c | 2 +- tests/misc/base64.pl | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/base64.c b/src/base64.c index 1f5c09aae..3ee5b3388 100644 --- a/src/base64.c +++ b/src/base64.c @@ -310,7 +310,7 @@ main (int argc, char **argv) if (argc - optind > 1) { - error (0, 0, _("extra operand %s"), quote (argv[optind])); + error (0, 0, _("extra operand %s"), quote (argv[optind+1])); usage (EXIT_FAILURE); } diff --git a/tests/misc/base64.pl b/tests/misc/base64.pl index 0eb8cf498..a544558cb 100755 --- a/tests/misc/base64.pl +++ b/tests/misc/base64.pl @@ -62,6 +62,7 @@ my @Tests; sub gen_tests($) { my ($prog) = @_; + my $try_help = "Try '$prog --help' for more information.\n"; @Tests= ( ['empty', {IN=>''}, {OUT=>""}], @@ -113,6 +114,12 @@ sub gen_tests($) ['b4k-1', '--decode', {IN=>$a3k_nl[1]}, {OUT=>'a' x (3072+0)}], ['b4k-2', '--decode', {IN=>$a3k_nl[2]}, {OUT=>'a' x (3072+0)}], ['b4k-3', '--decode', {IN=>$a3k_nl[3]}, {OUT=>'a' x (3072+0)}], + + ['ext-op1', 'a b', {IN=>''}, {EXIT=>1}, + {ERR => "$prog: extra operand 'b'\n" . $try_help}], + # Again, with more option arguments + ['ext-op2', '-di --wrap=40 a b', {IN=>''}, {EXIT=>1}, + {ERR => "$prog: extra operand 'b'\n" . $try_help}], ); if ($prog eq "base64") -- 2.11.0