"fix" for 5.36: pass the possible option value as an extra param
authorespie <espie@openbsd.org>
Sun, 21 May 2023 13:44:21 +0000 (13:44 +0000)
committerespie <espie@openbsd.org>
Sun, 21 May 2023 13:44:21 +0000 (13:44 +0000)
instead of defined/undefined, so that the code sub is called with
the right number of parameters.

usr.sbin/pkg_add/OpenBSD/Getopt.pm

index f382c3f..9871383 100644 (file)
@@ -1,5 +1,5 @@
 # ex:ts=8 sw=4:
-# $OpenBSD: Getopt.pm,v 1.14 2023/05/19 07:25:16 espie Exp $
+# $OpenBSD: Getopt.pm,v 1.15 2023/05/21 13:44:21 espie Exp $
 #
 # Copyright (c) 2006 Marc Espie <espie@openbsd.org>
 #
@@ -29,17 +29,17 @@ our @EXPORT = qw(getopts);
 
 sub handle_option
 {
-       my ($opt, $hash, $params) = @_;
+       my ($opt, $hash, @params) = @_;
 
        if (defined $hash->{$opt} and ref($hash->{$opt}) eq 'CODE') {
-               &{$hash->{$opt}}($params);
+               &{$hash->{$opt}}(@params);
        } else {
                no strict "refs";
                no strict "vars";
 
-               if (defined $params) {
-                       ${"opt_$opt"} = $params;
-                       $hash->{$opt} = $params;
+               if (@params > 0) {
+                       ${"opt_$opt"} = $params[0];
+                       $hash->{$opt} = $params[0];
                } else {
                        ${"opt_$opt"}++;
                        $hash->{$opt}++;