From f5def3a2a0d8913110936f9f4e13e37835754c28 Mon Sep 17 00:00:00 2001 From: Nicholas Clark Date: Sat, 7 Oct 2006 13:53:36 +0000 Subject: [PATCH] Change sprintf() to my_sprintf(), and use the returned length from that and my_snprintf() to avoid calls to strlen() p4raw-id: //depot/perl@28956 --- ext/Data/Dumper/Dumper.xs | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/ext/Data/Dumper/Dumper.xs b/ext/Data/Dumper/Dumper.xs index 8561216..e45550b 100644 --- a/ext/Data/Dumper/Dumper.xs +++ b/ext/Data/Dumper/Dumper.xs @@ -185,16 +185,7 @@ esc_q_utf8(pTHX_ SV* sv, register const char *src, register STRLEN slen) #endif *r++ = (char)k; else { - /* The return value of sprintf() is unportable. - * In modern systems it returns (int) the number of characters, - * but in older systems it might return (char*) the original - * buffer, or it might even be (void). The easiest portable - * thing to do is probably use sprintf() in void context and - * then strlen(buffer) for the length. The more proper way - * would of course be to figure out the prototype of sprintf. - * --jhi */ - sprintf(r, "\\x{%"UVxf"}", k); - r += strlen(r); + r = r + my_sprintf(r, "\\x{%"UVxf"}", k); } } *r++ = '"'; @@ -297,8 +288,7 @@ DD_dump(pTHX_ SV *val, const char *name, STRLEN namelen, SV *retval, HV *seenhv, ival = SvRV(val); realtype = SvTYPE(ival); - (void) my_snprintf(id, sizeof(id), "0x%"UVxf, PTR2UV(ival)); - idlen = strlen(id); + idlen = my_snprintf(id, sizeof(id), "0x%"UVxf, PTR2UV(ival)); if (SvOBJECT(ival)) realpack = HvNAME_get(SvSTASH(ival)); else @@ -506,8 +496,7 @@ DD_dump(pTHX_ SV *val, const char *name, STRLEN namelen, SV *retval, HV *seenhv, ilen = inamelen; sv_setiv(ixsv, ix); - (void) sprintf(iname+ilen, "%"IVdf, (IV)ix); - ilen = strlen(iname); + ilen = ilen + my_sprintf(iname+ilen, "%"IVdf, (IV)ix); iname[ilen++] = ']'; iname[ilen] = '\0'; if (indent >= 3) { sv_catsv(retval, totpad); @@ -776,8 +765,8 @@ DD_dump(pTHX_ SV *val, const char *name, STRLEN namelen, SV *retval, HV *seenhv, STRLEN i; if (namelen) { - (void) my_snprintf(id, sizeof(id), "0x%"UVxf, PTR2UV(val)); - if ((svp = hv_fetch(seenhv, id, (idlen = strlen(id)), FALSE)) && + idlen = my_snprintf(id, sizeof(id), "0x%"UVxf, PTR2UV(val)); + if ((svp = hv_fetch(seenhv, id, idlen, FALSE)) && (sv = *svp) && SvROK(sv) && (seenentry = (AV*)SvRV(sv))) { @@ -805,10 +794,9 @@ DD_dump(pTHX_ SV *val, const char *name, STRLEN namelen, SV *retval, HV *seenhv, if (DD_is_integer(val)) { STRLEN len; if (SvIsUV(val)) - (void) my_snprintf(tmpbuf, sizeof(tmpbuf), "%"UVuf, SvUV(val)); + len = my_snprintf(tmpbuf, sizeof(tmpbuf), "%"UVuf, SvUV(val)); else - (void) my_snprintf(tmpbuf, sizeof(tmpbuf), "%"IVdf, SvIV(val)); - len = strlen(tmpbuf); + len = my_snprintf(tmpbuf, sizeof(tmpbuf), "%"IVdf, SvIV(val)); if (SvPOK(val)) { /* Need to check to see if this is a string such as " 0". I'm assuming from sprintf isn't going to clash with utf8. @@ -1093,8 +1081,7 @@ Data_Dumper_Dumpxs(href, ...) STRLEN nchars; sv_setpvn(name, "$", 1); sv_catsv(name, varname); - (void) my_snprintf(tmpbuf, sizeof(tmpbuf), "%"IVdf, (IV)(i+1)); - nchars = strlen(tmpbuf); + nchars = my_snprintf(tmpbuf, sizeof(tmpbuf), "%"IVdf, (IV)(i+1)); sv_catpvn(name, tmpbuf, nchars); } -- 2.7.4