To make the current implementation of sv_replace sane, we should
authorNicholas Clark <nick@ccl4.org>
Thu, 25 Aug 2005 14:06:43 +0000 (14:06 +0000)
committerNicholas Clark <nick@ccl4.org>
Thu, 25 Aug 2005 14:06:43 +0000 (14:06 +0000)
assert that the reference count of the target is also 1.
(Given that we're splatting an SV with a reference count of 1 onto
the target)

p4raw-id: //depot/perl@25331

sv.c

diff --git a/sv.c b/sv.c
index 5089825..66f3dc0 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -5409,9 +5409,13 @@ Perl_sv_replace(pTHX_ register SV *sv, register SV *nsv)
     const U32 refcnt = SvREFCNT(sv);
     SV_CHECK_THINKFIRST_COW_DROP(sv);
     if (SvREFCNT(nsv) != 1) {
-       Perl_croak(aTHX_ "panic: feference miscount on nsv in sv_replace() (%"
+       Perl_croak(aTHX_ "panic: reference miscount on nsv in sv_replace() (%"
                   UVuf " != 1)", (UV) SvREFCNT(nsv));
     }
+    if (SvREFCNT(sv) != 1) {
+       Perl_croak(aTHX_ "panic: reference miscount on sv in sv_replace() (%"
+                  UVuf " != 1)", (UV) SvREFCNT(sv));
+    }
     if (SvMAGICAL(sv)) {
        if (SvMAGICAL(nsv))
            mg_free(nsv);