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
authorSlaven Rezic <slaven@rezic.de>
Sat, 1 Aug 1998 13:38:03 +0000 (15:38 +0200)
committerGurusamy Sarathy <gsar@cpan.org>
Sun, 2 Aug 1998 06:56:37 +0000 (06:56 +0000)
Message-Id: <199808011138.NAA05189@mail.cs.tu-berlin.de>
Subject: Data::Dumper 2.09, patch

p4raw-id: //depot/maint-5.005/perl@1706

ext/Data/Dumper/Dumper.xs

index 6add52f..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;
 }
@@ -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)