From: Vincent Pit Date: Sun, 4 Jan 2009 13:32:32 +0000 (+0100) Subject: Fix segfault when localizing array elements with an invalid negative index X-Git-Tag: v0.03~3 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;ds=inline;h=33d8f50585aa060e71a82a5fd414e114e9b1c1c1;p=perl%2Fmodules%2FScope-Upper.git Fix segfault when localizing array elements with an invalid negative index --- diff --git a/Upper.xs b/Upper.xs index b2344b9..657f01c 100644 --- a/Upper.xs +++ b/Upper.xs @@ -115,7 +115,7 @@ STATIC void su_save_aelem(pTHX_ AV *av, SV *key, SV *val) { preeminent = av_exists(av, idx); svp = av_fetch(av, idx, 1); - if (!*svp || *svp == &PL_sv_undef) croak(PL_no_aelem, idx); + if (!svp || *svp == &PL_sv_undef) croak(PL_no_aelem, idx); if (preeminent) save_aelem(av, idx, svp); diff --git a/t/39-localize_elem-target.t b/t/39-localize_elem-target.t index ecff42b..fe538e4 100644 --- a/t/39-localize_elem-target.t +++ b/t/39-localize_elem-target.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 17; +use Test::More tests => 21; use Scope::Upper qw/localize_elem/; @@ -29,6 +29,24 @@ our @a; is_deeply \@a, [ 4 .. 6 ], 'localize_elem "@a", 4, 8, 0 [end]'; } +{ + local @a = (4 .. 6); + { + localize_elem '@main::a', -2, 8, 0; + is_deeply \@a, [ 4, 8, 6 ], 'localize_elem "@a", -2, 8, 0 [ok]'; + } + is_deeply \@a, [ 4 .. 6 ], 'localize_elem "@a", -2, 8, 0 [end]'; +} + +{ + local @a = (4 .. 6); + { + eval { localize_elem '@main::a', -4, 8, 0 }; + like $@, qr/Modification of non-creatable array value attempted, subscript -4/, 'localize_elem "@a", -4, 8, 0 [ok]'; + } + is_deeply \@a, [ 4 .. 6 ], 'localize_elem "@a", -4, 8, 0 [end]'; +} + { local @a = (4 .. 6); {