This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
PATCH: sv_rvweaken() deficiency (against 5.8.0)
authorMark Mielke <mark@mark.mielke.cc>
Mon, 20 Jan 2003 19:56:13 +0000 (14:56 -0500)
committerhv <hv@crypt.org>
Tue, 11 Feb 2003 00:27:56 +0000 (00:27 +0000)
Message-ID: <20030121005613.GA31739@mark.mielke.cc>

p4raw-id: //depot/perl@18691

sv.c

diff --git a/sv.c b/sv.c
index 52a629c..6c8eb65 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -4964,7 +4964,19 @@ S_sv_add_backref(pTHX_ SV *tsv, SV *sv)
        sv_magic(tsv, (SV*)av, PERL_MAGIC_backref, NULL, 0);
        SvREFCNT_dec(av);           /* for sv_magic */
     }
-    av_push(av,sv);
+    if (AvFILLp(av) >= AvMAX(av)) {
+        SV **svp = AvARRAY(av);
+        I32 i = AvFILLp(av);
+        while (i >= 0) {
+            if (svp[i] == &PL_sv_undef) {
+                svp[i] = sv;        /* reuse the slot */
+                return;
+            }
+            i--;
+        }
+        av_extend(av, AvFILLp(av)+1);
+    }
+    AvARRAY(av)[++AvFILLp(av)] = sv; /* av_push() */
 }
 
 /* delete a back-reference to ourselves from the backref magic associated