summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Vincent <jesse@bestpractical.com>2010-03-31 13:31:55 -0400
committerJesse Vincent <jesse@bestpractical.com>2010-03-31 13:31:55 -0400
commit87bf445dc0511a8b81330bf16611ddac4a331e88 (patch)
tree123c30e20f0cb546523fa1dc5a61a28e4383b6e9
parent34153154f350f3b82aece60c34df357ea74b5732 (diff)
parent95a26d8e5a73b4fe66d7b066732f59cd675632d0 (diff)
downloadperl-87bf445dc0511a8b81330bf16611ddac4a331e88.tar.gz
Merge branch 'blead' of ssh://perl5.git.perl.org/gitroot/perl into blead
* 'blead' of ssh://perl5.git.perl.org/gitroot/perl: Don't initialize end in pp_reverse when begin is NULL More tests for in-place reverse (empty tied array) Add a test for reversing in-place an empty array Avoid a segfault when reversing an empty array in-place.
-rw-r--r--pp.c13
-rw-r--r--t/op/reverse.t10
2 files changed, 17 insertions, 6 deletions
diff --git a/pp.c b/pp.c
index 5876cfd607..e4660b31f2 100644
--- a/pp.c
+++ b/pp.c
@@ -5418,12 +5418,15 @@ PP(pp_reverse)
}
else {
SV **begin = AvARRAY(av);
- SV **end = begin + AvFILLp(av);
- while (begin < end) {
- register SV * const tmp = *begin;
- *begin++ = *end;
- *end-- = tmp;
+ if (begin) {
+ SV **end = begin + AvFILLp(av);
+
+ while (begin < end) {
+ register SV * const tmp = *begin;
+ *begin++ = *end;
+ *end-- = tmp;
+ }
}
}
}
diff --git a/t/op/reverse.t b/t/op/reverse.t
index 1ad727ace9..2fa0877202 100644
--- a/t/op/reverse.t
+++ b/t/op/reverse.t
@@ -6,7 +6,7 @@ BEGIN {
require './test.pl';
}
-plan tests => 21;
+plan tests => 23;
is(reverse("abc"), "cba");
@@ -44,6 +44,10 @@ is(reverse(), "raboof");
@a = reverse @a;
ok(!exists $a[2] && !exists $a[3]);
is($a[0] . $a[1] . $a[4], '985');
+
+ my @empty;
+ @empty = reverse @empty;
+ is("@empty", "");
}
use Tie::Array;
@@ -73,6 +77,10 @@ use Tie::Array;
@a = reverse @a;
ok(!exists $a[2] && !exists $a[3]);
is($a[0] . $a[1] . $a[4], '985');
+
+ tie my @empty, "Tie::StdArray";
+ @empty = reverse @empty;
+ is(scalar(@empty), 0);
}
{