From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 074CC1F9F4; Mon, 27 Sep 2021 21:05:46 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Cc: Konstantin Ryabitsev Subject: [PATCH 3/3] lei completion: workaround old Perl bug Date: Mon, 27 Sep 2021 16:05:45 -0500 Message-Id: <20210927210545.23941-4-e@80x24.org> In-Reply-To: <20210927210545.23941-1-e@80x24.org> References: <20210927210545.23941-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: While `$argv[-1]' is `undef' on an empty @argv, using `$argv[-1]' as a subroutine argument would fail incorrectly with: Modification of non-creatable array value attempted, subscript -1 at ... ...even though we'd never attempt to modify @_ itself in the subroutines being called. Work around the bug (tested on 5.16.3) by passing `undef' explicitly when `$argv[-1]' is already `undef'. Reported-by: Konstantin Ryabitsev Link: https://public-inbox.org/meta/20210927124056.kj5okiefvs4ztk27@meerkat.local/ --- lib/PublicInbox/LeiExportKw.pm | 2 +- lib/PublicInbox/LeiImport.pm | 4 ++-- lib/PublicInbox/LeiLsMailSource.pm | 4 ++-- lib/PublicInbox/LeiRefreshMailSync.pm | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/PublicInbox/LeiExportKw.pm b/lib/PublicInbox/LeiExportKw.pm index cea9beeb5694..0b65c2762633 100644 --- a/lib/PublicInbox/LeiExportKw.pm +++ b/lib/PublicInbox/LeiExportKw.pm @@ -131,7 +131,7 @@ sub _complete_export_kw { my $match_cb = $lei->complete_url_prepare(\@argv); # filter-out read-only sources: my @k = grep(!m!(?://;AUTH=ANONYMOUS\@|\A(?:nntps?|s?news)://)!, - $lms->folders($argv[-1], 1)); + $lms->folders($argv[-1] // undef, 1)); my @m = map { $match_cb->($_) } @k; @m ? @m : @k; } diff --git a/lib/PublicInbox/LeiImport.pm b/lib/PublicInbox/LeiImport.pm index 397292d4c787..69d63ab6b397 100644 --- a/lib/PublicInbox/LeiImport.pm +++ b/lib/PublicInbox/LeiImport.pm @@ -122,11 +122,11 @@ sub lei_import { # the main "lei import" method sub _complete_import { my ($lei, @argv) = @_; my ($re, $cur, $match_cb) = $lei->complete_url_prepare(\@argv); - my @k = $lei->url_folder_cache->keys($argv[-1], 1); + my @k = $lei->url_folder_cache->keys($argv[-1] // undef, 1); my @m = map { $match_cb->($_) } @k; my %f = map { $_ => 1 } (@m ? @m : @k); if (my $lms = $lei->lms) { - @k = $lms->folders($argv[-1], 1); + @k = $lms->folders($argv[-1] // undef, 1); @m = map { $match_cb->($_) } @k; if (@m) { @f{@m} = @m } else { @f{@k} = @k } } diff --git a/lib/PublicInbox/LeiLsMailSource.pm b/lib/PublicInbox/LeiLsMailSource.pm index 1db15d5742b5..7c3c0cda18d6 100644 --- a/lib/PublicInbox/LeiLsMailSource.pm +++ b/lib/PublicInbox/LeiLsMailSource.pm @@ -107,11 +107,11 @@ sub lei_ls_mail_source { sub _complete_ls_mail_source { my ($lei, @argv) = @_; my $match_cb = $lei->complete_url_prepare(\@argv); - my @k = $lei->url_folder_cache->keys($argv[-1], 1); + my @k = $lei->url_folder_cache->keys($argv[-1] // undef, 1); my @m = map { $match_cb->($_) } @k; my %f = map { $_ => 1 } (@m ? @m : @k); if (my $lms = $lei->lms) { - @k = $lms->folders($argv[-1], 1); + @k = $lms->folders($argv[-1] // undef, 1); @m = map { $match_cb->($_) } grep(m!\A[a-z]+://!, @k); if (@m) { @f{@m} = @m } else { @f{@k} = @k } } diff --git a/lib/PublicInbox/LeiRefreshMailSync.pm b/lib/PublicInbox/LeiRefreshMailSync.pm index eb842843b51d..0cb9f3dccd48 100644 --- a/lib/PublicInbox/LeiRefreshMailSync.pm +++ b/lib/PublicInbox/LeiRefreshMailSync.pm @@ -101,7 +101,7 @@ sub _complete_refresh_mail_sync { my ($lei, @argv) = @_; my $lms = $lei->lms or return (); my $match_cb = $lei->complete_url_prepare(\@argv); - my @k = $lms->folders($argv[-1], 1); + my @k = $lms->folders($argv[-1] // undef, 1); my @m = map { $match_cb->($_) } @k; @m ? @m : @k }