summaryrefslogtreecommitdiff
path: root/ext/Data
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2006-10-07 13:53:36 +0000
committerNicholas Clark <nick@ccl4.org>2006-10-07 13:53:36 +0000
commitf5def3a2a0d8913110936f9f4e13e37835754c28 (patch)
tree34e0590b7e82664e80a743915e88388a55931266 /ext/Data
parent9ac4c1072a98d8d5ad54c6972c40921620c69d8e (diff)
downloadperl-f5def3a2a0d8913110936f9f4e13e37835754c28.tar.gz
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
Diffstat (limited to 'ext/Data')
-rw-r--r--ext/Data/Dumper/Dumper.xs29
1 files changed, 8 insertions, 21 deletions
diff --git a/ext/Data/Dumper/Dumper.xs b/ext/Data/Dumper/Dumper.xs
index 85612163fd..e45550b157 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);
}