From: Peter Martini Date: Mon, 3 Jan 2011 06:54:04 +0000 (-0800) Subject: [perl #45147] Issue with the exists function X-Git-Tag: accepted/trunk/20130322.191538~6293 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=54a4274e3c68e0e5bc9baaef00b55c43097929a7;p=platform%2Fupstream%2Fperl.git [perl #45147] Issue with the exists function Perl_av_exists tested to see if regdata magic was present, but did not have any logic to fetch that data in the positive key case. Additionally, in the negative key case, if AvFILL indicated the key existed, it wouldn't return, and would then fall through to the logic that treated it like a real array. --- diff --git a/AUTHORS b/AUTHORS index f27059d..5ae2362 100644 --- a/AUTHORS +++ b/AUTHORS @@ -821,6 +821,7 @@ Peter J. Farley III Peter J. Holzer Peter Jaspers-Fayer Peter John Acklam +Peter Martini Peter O'Gorman Peter Prymmer Peter Rabbitson diff --git a/av.c b/av.c index d6db6bf..8408220 100644 --- a/av.c +++ b/av.c @@ -901,7 +901,9 @@ Perl_av_exists(pTHX_ AV *av, I32 key) if (SvRMAGICAL(av)) { const MAGIC * const tied_magic = mg_find((const SV *)av, PERL_MAGIC_tied); - if (tied_magic || mg_find((const SV *)av, PERL_MAGIC_regdata)) { + const MAGIC * const regdata_magic + = mg_find((const SV *)av, PERL_MAGIC_regdata); + if (tied_magic || regdata_magic) { SV * const sv = sv_newmortal(); MAGIC *mg; /* Handle negative array indices 20020222 MJD */ @@ -920,9 +922,18 @@ Perl_av_exists(pTHX_ AV *av, I32 key) key += AvFILL(av) + 1; if (key < 0) return FALSE; + else + return TRUE; } } + if(key >= 0 && regdata_magic) { + if (key <= AvFILL(av)) + return TRUE; + else + return FALSE; + } + mg_copy(MUTABLE_SV(av), sv, 0, key); mg = mg_find(sv, PERL_MAGIC_tiedelem); if (mg) { diff --git a/t/re/pat.t b/t/re/pat.t index 6c3af0a..2dd9503 100644 --- a/t/re/pat.t +++ b/t/re/pat.t @@ -23,7 +23,7 @@ BEGIN { } -plan tests => 411; # Update this when adding/deleting tests. +plan tests => 423; # Update this when adding/deleting tests. run_tests() unless caller; @@ -640,6 +640,19 @@ sub run_tests { ok !defined $+ [3] && !defined $- [3] && !defined $+ [4] && !defined $- [4]; + # Exists has a special check for @-/@+ - bug 45147 + ok exists $-[0]; + ok exists $+[0]; + ok exists $-[2]; + ok exists $+[2]; + ok !exists $-[3]; + ok !exists $+[3]; + ok exists $-[-1]; + ok exists $+[-1]; + ok exists $-[-3]; + ok exists $+[-3]; + ok !exists $-[-4]; + ok !exists $+[-4]; /.(a)(b)?(a)/; iseq $#+, 3;