sv_2pv_flags shouldn't return a constant string "NULLREF" - it was the
Nicholas Clark [Tue, 6 Dec 2005 12:19:23 +0000 (12:19 +0000)]
only constant non-"" string returned.

p4raw-id: //depot/perl@26272

sv.c

diff --git a/sv.c b/sv.c
index 0378b1f..55bb674 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -2584,15 +2584,12 @@ Perl_sv_2pv_flags(pTHX_ register SV *sv, STRLEN *lp, I32 flags)
                const SV *const referent = (SV*)SvRV(sv);
 
                if (!referent) {
-                   if (lp)
-                       *lp = 7;
-                   return (char *)"NULLREF";
-               }
-               
-               if (SvTYPE(referent) == SVt_PVMG && ((SvFLAGS(referent) &
-                          (SVs_OBJECT|SVf_OK|SVs_GMG|SVs_SMG|SVs_RMG))
-                         == (SVs_OBJECT|SVs_SMG))
-                   && (mg = mg_find(referent, PERL_MAGIC_qr))) {
+                   tsv = sv_2mortal(newSVpvn("NULLREF", 7));
+               } else if (SvTYPE(referent) == SVt_PVMG
+                          && ((SvFLAGS(referent) &
+                               (SVs_OBJECT|SVf_OK|SVs_GMG|SVs_SMG|SVs_RMG))
+                              == (SVs_OBJECT|SVs_SMG))
+                          && (mg = mg_find(referent, PERL_MAGIC_qr))) {
                    const regexp *re = (regexp *)mg->mg_obj;
 
                    if (!mg->mg_ptr) {
@@ -2683,10 +2680,10 @@ Perl_sv_2pv_flags(pTHX_ register SV *sv, STRLEN *lp, I32 flags)
                    else
                        Perl_sv_setpvf(aTHX_ tsv, "%s(0x%"UVxf")", typestr,
                                       PTR2UV(referent));
-                   if (lp)
-                       *lp = SvCUR(tsv);
-                   return SvPVX(tsv);
                }
+               if (lp)
+                   *lp = SvCUR(tsv);
+               return SvPVX(tsv);
            }
        }
        if (SvREADONLY(sv) && !SvOK(sv)) {