Permalink
Browse files

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.
  • Loading branch information...
2 parents 3415315 + 95a26d8 commit 87bf445dc0511a8b81330bf16611ddac4a331e88 @obra obra committed Mar 31, 2010
Showing with 17 additions and 6 deletions.
  1. +8 −5 pp.c
  2. +9 −1 t/op/reverse.t
View
13 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;
+ }
}
}
}
View
@@ -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);
}
{

0 comments on commit 87bf445

Please sign in to comment.