diff options
author | Karl Williamson <khw@cpan.org> | 2019-06-01 14:39:55 -0600 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2019-06-27 09:36:35 -0600 |
commit | bc62bf8519f9005df2fb29dbd3d330202b258b6b (patch) | |
tree | 3ccdb243600b6cf92743c87627115193c8b68e38 /av.c | |
parent | 1bed9104d475eb126ab7d1df518bb894f66e1fab (diff) | |
download | perl-bc62bf8519f9005df2fb29dbd3d330202b258b6b.tar.gz |
Add some defensive coding to av_store()
Don't decrement the reference count of the element about to be stored
into.
Likely, this is an error in the caller, but doing this action blindly is
like shooting yourself in the foot. The branch prediction also added
ensures this shouldn't slow things down.
See http://nntp.perl.org/group/perl.perl5.porters/254974
Diffstat (limited to 'av.c')
-rw-r--r-- | av.c | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -356,8 +356,8 @@ Perl_av_store(pTHX_ AV *av, SSize_t key, SV *val) } AvFILLp(av) = key; } - else if (AvREAL(av)) - SvREFCNT_dec(ary[key]); + else if (AvREAL(av) && LIKELY(ary[key] != val)) + SvREFCNT_dec(ary[key]); ary[key] = val; if (SvSMAGICAL(av)) { const MAGIC *mg = SvMAGIC(av); |