This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fix quoting of keys with embedded nulls
[perl5.git] / ext / Data / Dumper / Dumper.xs
index 07e82d5..d8012ee 100644 (file)
@@ -5,7 +5,7 @@
 static SV      *freezer;
 static SV      *toaster;
 
-static I32 num_q _((char *s));
+static I32 num_q _((char *s, STRLEN slen));
 static I32 esc_q _((char *dest, char *src, STRLEN slen));
 static SV *sv_x _((SV *sv, char *str, STRLEN len, I32 n));
 static I32 DD_dump _((SV *val, char *name, STRLEN namelen, SV *retval,
@@ -42,14 +42,15 @@ TOP:
 
 /* count the number of "'"s and "\"s in string */
 static I32
-num_q(register char *s)
+num_q(register char *s, register STRLEN slen)
 {
     register I32 ret = 0;
-    
-    while (*s) {
+
+    while (slen > 0) {
        if (*s == '\'' || *s == '\\')
            ++ret;
        ++s;
+       --slen;
     }
     return ret;
 }
@@ -138,7 +139,7 @@ DD_dump(SV *val, char *name, STRLEN namelen, SV *retval, HV *seenhv,
     
     if (SvGMAGICAL(val))
         mg_get(val);
-    if (val == &sv_undef || !SvOK(val)) {
+    if (val == &PL_sv_undef || !SvOK(val)) {
        sv_catpvn(retval, "undef", 5);
        return 1;
     }
@@ -151,9 +152,9 @@ DD_dump(SV *val, char *name, STRLEN namelen, SV *retval, HV *seenhv,
            XPUSHs(val); PUTBACK;
            i = perl_call_method(SvPVX(freezer), G_EVAL|G_SCALAR);
            SPAGAIN;
-           if (SvTRUE(GvSV(errgv)))
+           if (SvTRUE(GvSV(PL_errgv)))
                warn("WARNING(Freezer method call failed): %s",
-                    SvPVX(GvSV(errgv)));
+                    SvPVX(GvSV(PL_errgv)));
            else if (i)
                val = newSVsv(POPs);
            PUTBACK; FREETMPS; LEAVE;
@@ -302,7 +303,7 @@ DD_dump(SV *val, char *name, STRLEN namelen, SV *retval, HV *seenhv,
                if (svp)
                    elem = *svp;
                else
-                   elem = &sv_undef;
+                   elem = &PL_sv_undef;
                
                ilen = inamelen;
                sv_setiv(ixsv, ix);
@@ -380,7 +381,7 @@ DD_dump(SV *val, char *name, STRLEN namelen, SV *retval, HV *seenhv,
                hval = hv_iterval((HV*)ival, entry);
 
                if (quotekeys || needs_quote(key)) {
-                   nticks = num_q(key);
+                   nticks = num_q(key, klen);
                    New(0, nkey, klen+nticks+3, char);
                    nkey[0] = '\'';
                    if (nticks)
@@ -640,7 +641,7 @@ Data_Dumper_Dumpxs(href, ...)
            todumpav = namesav = Nullav;
            seenhv = Nullhv;
            val = pad = xpad = apad = sep = tmp = varname
-               = freezer = toaster = bless = &sv_undef;
+               = freezer = toaster = bless = &PL_sv_undef;
            name = sv_newmortal();
            indent = 2;
            terse = useqq = purity = deepcopy = 0;
@@ -699,7 +700,7 @@ Data_Dumper_Dumpxs(href, ...)
                    if ((svp = av_fetch(todumpav, i, FALSE)))
                        val = *svp;
                    else
-                       val = &sv_undef;
+                       val = &PL_sv_undef;
                    if ((svp = av_fetch(namesav, i, TRUE)))
                        sv_setsv(name, *svp);
                    else