summaryrefslogtreecommitdiff
path: root/av.c
diff options
context:
space:
mode:
authorPeter Martini <PeterCMartini@GMail.com>2011-01-02 22:54:04 -0800
committerFather Chrysostomos <sprout@cpan.org>2011-01-02 23:48:19 -0800
commit54a4274e3c68e0e5bc9baaef00b55c43097929a7 (patch)
tree3d538940dd33d4be17dac346936f85ba73b34489 /av.c
parent2831a86cee065b53b74fd19ddcc6a4257484646d (diff)
downloadperl-54a4274e3c68e0e5bc9baaef00b55c43097929a7.tar.gz
[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.
Diffstat (limited to 'av.c')
-rw-r--r--av.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/av.c b/av.c
index d6db6bf195..8408220aff 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) {