Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.94k stars 554 forks source link

"splice() offset past end of array" warning doesn't always appear #12927

Closed p5pRT closed 11 years ago

p5pRT commented 11 years ago

Migrated from rt.perl.org#117729 (status was 'resolved')

Searchable as RT117729$

p5pRT commented 11 years ago

From @karenetheridge

According to the splice documentation in perlfunc​:

  splice ARRAY or EXPR\,OFFSET

  If OFFSET is past the end of the array\, Perl issues a warning\, and   splices at the end of the array.

Consider​:   perl -wle'use warnings FATAL => "all"; my @​arr = qw(0 .. 10); splice(@​arr\, 20); print "ar is @​arr"'

This generates a warning on some versions/architectures and not others. Based on the versions tested\, this appears to have regressed between 5.14.3 and 5.16.0.

warning​: 5.8.9 darwin OSX 10.6.8 5.14.2 darwin OSX 10.6.8 5.14.3 darwin OSX 10.6.8 5.14.3 linux CentOS

no warning​: 5.16.0 linux ubuntu 5.16.0 darwin OSX 10.6.8 5.16.1 darwin OSX 10.6.8 5.16.3 darwin OSX 10.6.8 5.17.11 darwin OSX 10.6.8

p5pRT commented 11 years ago

From @jkeenan

On Tue Apr 23 13​:14​:02 2013\, perl@​froods.org wrote​:

According to the splice documentation in perlfunc​:

splice ARRAY or EXPR\,OFFSET

If OFFSET is past the end of the array\, Perl issues a warning\, and splices at the end of the array.

Consider​: perl -wle'use warnings FATAL => "all"; my @​arr = qw(0 .. 10); splice(@​arr\, 20); print "ar is @​arr"'

This generates a warning on some versions/architectures and not others. Based on the versions tested\, this appears to have regressed between 5.14.3 and 5.16.0.

warning​: 5.8.9 darwin OSX 10.6.8 5.14.2 darwin OSX 10.6.8 5.14.3 darwin OSX 10.6.8 5.14.3 linux CentOS

no warning​: 5.16.0 linux ubuntu 5.16.0 darwin OSX 10.6.8 5.16.1 darwin OSX 10.6.8 5.16.3 darwin OSX 10.6.8 5.17.11 darwin OSX 10.6.8

Confirmed to occur in blead as well.

p5pRT commented 11 years ago

The RT System itself - Status changed from 'new' to 'open'

p5pRT commented 11 years ago

From @ikegami

It's not a regression; it's an intentional change.

C\<\< splice(@​a\, $n) >> is commonly used to truncate an array if it's too large\, so C\<\< splice(@​a\, $n) >> (with no further args) does not warn even if @​a\<$n.

See https://rt-archive.perl.org/perl5/Public/Bug/Display.html?id=78462 http​://perl5.git.perl.org/perl.git/commitdiff/5cd408a276e19848774860967c3ec06b67b863ee?hp=0890f1a536cff0aff68038cae78e02c9d9b6a2b2

So\, this is merely a documentation bug for which I'll submit a patch tomorrow.

- Eric

On Tue\, Apr 23\, 2013 at 8​:34 PM\, James E Keenan via RT \< perlbug-followup@​perl.org> wrote​:

On Tue Apr 23 13​:14​:02 2013\, perl@​froods.org wrote​:

According to the splice documentation in perlfunc​:

splice ARRAY or EXPR\,OFFSET

If OFFSET is past the end of the array\, Perl issues a warning\, and splices at the end of the array.

Consider​: perl -wle'use warnings FATAL => "all"; my @​arr = qw(0 .. 10); splice(@​arr\, 20); print "ar is @​arr"'

This generates a warning on some versions/architectures and not others. Based on the versions tested\, this appears to have regressed between 5.14.3 and 5.16.0.

warning​: 5.8.9 darwin OSX 10.6.8 5.14.2 darwin OSX 10.6.8 5.14.3 darwin OSX 10.6.8 5.14.3 linux CentOS

no warning​: 5.16.0 linux ubuntu 5.16.0 darwin OSX 10.6.8 5.16.1 darwin OSX 10.6.8 5.16.3 darwin OSX 10.6.8 5.17.11 darwin OSX 10.6.8

Confirmed to occur in blead as well.

--- via perlbug​: queue​: perl5 status​: new https://rt-archive.perl.org/perl5/Ticket/Display.html?id=117729

p5pRT commented 11 years ago

From @karenetheridge

On Tue\, Apr 23\, 2013 at 09​:52​:07PM -0700\, Eric Brine via RT wrote​:

It's not a regression; it's an intentional change.

C\<\< splice(@​a\, $n) >> is commonly used to truncate an array if it's too large\, so C\<\< splice(@​a\, $n) >> (with no further args) does not warn even if @​a\<$n.

This is quite reasonable (and indeed\, this is the exact usecase where I discovered that there was a warning on my not-quite-as-current production system). :)

So\, this is merely a documentation bug for which I'll submit a patch tomorrow.

Thanks! (Was there also a perldelta entry for this? it's not too late to put one in perldelta5160.)

p5pRT commented 11 years ago

From @ikegami

On Wed\, Apr 24\, 2013 at 10​:47 AM\, Karen Etheridge \perl@&#8203;froods\.org wrote​:

On Tue\, Apr 23\, 2013 at 09​:52​:07PM -0700\, Eric Brine via RT wrote​:

So\, this is merely a documentation bug for which I'll submit a patch

tomorrow.

Thanks! (Was there also a perldelta entry for this? it's not too late to

put one in perldelta5160.)

Patched attached. Ok\, it's not "tomorrow"\, but I figured I'd wait til 5.18 was out.

It actually is too late to add to perldelta5160\, but it was actually mentioned.

p5pRT commented 11 years ago

From @ikegami

0001-Adjust-documentation-for-removal-of-splice-warning.patch ```diff From b4f8845653bc5261c5f8827c3edad6747396b651 Mon Sep 17 00:00:00 2001 From: Eric Brine Date: Sun, 2 Jun 2013 21:46:07 -0700 Subject: [PATCH] Adjust documentation for removal of splice warning --- pod/perlfunc.pod | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index 5c6b4f8..3b36873 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -6766,8 +6766,8 @@ If LENGTH is omitted, removes everything from OFFSET onward. If LENGTH is negative, removes the elements from OFFSET onward except for -LENGTH elements at the end of the array. If both OFFSET and LENGTH are omitted, removes everything. If OFFSET is -past the end of the array, Perl issues a warning, and splices at the -end of the array. +past the end of the array and a LENGTH was provided, Perl issues a warning, +and splices at the end of the array. The following equivalences hold (assuming C<< $#a >= $i >> ) -- 1.7.2.5 ```
p5pRT commented 11 years ago

From @cpansprout

On Sun Jun 02 21​:44​:25 2013\, ikegami@​adaelis.com wrote​:

On Wed\, Apr 24\, 2013 at 10​:47 AM\, Karen Etheridge \perl@&#8203;froods\.org wrote​:

On Tue\, Apr 23\, 2013 at 09​:52​:07PM -0700\, Eric Brine via RT wrote​:

So\, this is merely a documentation bug for which I'll submit a patch

tomorrow.

Thanks! (Was there also a perldelta entry for this? it's not too late to

put one in perldelta5160.)

Patched attached. Ok\, it's not "tomorrow"\, but I figured I'd wait til 5.18 was out.

Thank you. Applied as 8e602cc.

--

Father Chrysostomos

p5pRT commented 11 years ago

@cpansprout - Status changed from 'open' to 'resolved'