Change 14939 by jhi@alpha on 2002/03/02 02:27:05
Subject: PATCH: "splice() offset past end of array" warning. (take 2)
From: Schuyler Erle <[EMAIL PROTECTED]>
Date: Fri, 01 Mar 2002 14:22:19 -0800
Message-ID: <[EMAIL PROTECTED]>
Subject: Re: PATCH: "splice() offset past end of array" warning.
From: Mark-Jason Dominus <[EMAIL PROTECTED]>
Date: Fri, 01 Mar 2002 17:19:49 -0500
Message-ID: <[EMAIL PROTECTED]>
Affected files ...
.... //depot/perl/pod/perldiag.pod#277 edit
.... //depot/perl/pod/perlfunc.pod#300 edit
.... //depot/perl/pp.c#335 edit
.... //depot/perl/t/op/splice.t#5 edit
Differences ...
==== //depot/perl/pod/perldiag.pod#277 (text) ====
Index: perl/pod/perldiag.pod
--- perl/pod/perldiag.pod.~1~ Fri Mar 1 19:30:06 2002
+++ perl/pod/perldiag.pod Fri Mar 1 19:30:06 2002
@@ -3311,6 +3311,14 @@
(F) A sort comparison subroutine may not return a list value with more
or less than one element. See L<perlfunc/sort>.
+=item splice() offset past end of array
+
+(W misc) You attempted to specify an offset that was past the end of
+the array passed to splice(). Splicing will instead commence at the end
+of the array, rather than past it. If this isn't what you want, try
+explicitly pre-extending the array by assigning $#array = $offset. See
+L<perlfunc/splice>.
+
=item Split loop
(P) The split was looping infinitely. (Obviously, a split shouldn't
==== //depot/perl/pod/perlfunc.pod#300 (text) ====
Index: perl/pod/perlfunc.pod
--- perl/pod/perlfunc.pod.~1~ Fri Mar 1 19:30:06 2002
+++ perl/pod/perlfunc.pod Fri Mar 1 19:30:06 2002
@@ -4641,7 +4641,9 @@
If OFFSET is negative then it starts that far from the end of the array.
If LENGTH is omitted, removes everything from OFFSET onward.
If LENGTH is negative, leaves that many elements off the end of the array.
-If both OFFSET and LENGTH are omitted, removes everything.
+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.
The following equivalences hold (assuming C<$[ == 0>):
==== //depot/perl/pp.c#335 (text) ====
Index: perl/pp.c
--- perl/pp.c.~1~ Fri Mar 1 19:30:06 2002
+++ perl/pp.c Fri Mar 1 19:30:06 2002
@@ -3926,8 +3926,11 @@
offset = 0;
length = AvMAX(ary) + 1;
}
- if (offset > AvFILLp(ary) + 1)
+ if (offset > AvFILLp(ary) + 1) {
+ if (ckWARN(WARN_MISC))
+ Perl_warner(aTHX_ WARN_MISC, "splice() offset past end of array" );
offset = AvFILLp(ary) + 1;
+ }
after = AvFILLp(ary) + 1 - (offset + length);
if (after < 0) { /* not that much array */
length += after; /* offset+length now in array */
==== //depot/perl/t/op/splice.t#5 (xtext) ====
Index: perl/t/op/splice.t
--- perl/t/op/splice.t.~1~ Fri Mar 1 19:30:06 2002
+++ perl/t/op/splice.t Fri Mar 1 19:30:06 2002
@@ -21,7 +21,7 @@
print "not " unless j(splice(@a,5,1,5)) eq "5" && j(@a) eq j(0..11);
print "ok 5\n";
-print "not " unless j(splice(@a, 20, 0, 12, 13)) eq "" && j(@a) eq j(0..13);
+print "not " unless j(splice(@a, @a, 0, 12, 13)) eq "" && j(@a) eq j(0..13);
print "ok 6\n";
print "not " unless j(splice(@a, -@a, @a, 1, 2, 3)) eq j(0..13) && j(@a) eq j(1..3);
End of Patch.