diff options
author | Gurusamy Sarathy <gsar@cpan.org> | 2000-02-07 21:21:44 +0000 |
---|---|---|
committer | Gurusamy Sarathy <gsar@cpan.org> | 2000-02-07 21:21:44 +0000 |
commit | 14e3446afc4b26de16f96428f6be3ee9338f0215 (patch) | |
tree | 6c9d0ebdf2db11c0548cdeb7d293fa12380426a1 /sv.c | |
parent | 151210d1da6387892e1804f7c0c65f5a4da5f893 (diff) | |
download | perl-14e3446afc4b26de16f96428f6be3ee9338f0215.tar.gz |
sprintf("%v"...) buffer resizing busted
p4raw-id: //depot/perl@5035
Diffstat (limited to 'sv.c')
-rw-r--r-- | sv.c | 15 |
1 files changed, 9 insertions, 6 deletions
@@ -5883,9 +5883,10 @@ Perl_sv_vcatpvfn(pTHX_ SV *sv, const char *pat, STRLEN patlen, va_list *args, SV { STRLEN len; U8 *str = (U8*)SvPVx(argsv,len); - I32 vlen = len*3; + I32 vlen = len*3+1; SV *vsv = NEWSV(73,vlen); I32 ulen; + I32 vfree = vlen; U8 *vptr = (U8*)SvPVX(vsv); STRLEN vcur = 0; bool utf = DO_UTF8(argsv); @@ -5904,19 +5905,21 @@ Perl_sv_vcatpvfn(pTHX_ SV *sv, const char *pat, STRLEN patlen, va_list *args, SV str += ulen; len -= ulen; eptr = ebuf + sizeof ebuf; - if (elen >= vlen-1) { + do { + *--eptr = '0' + uv % 10; + } while (uv /= 10); + elen = (ebuf + sizeof ebuf) - eptr; + while (elen >= vfree-1) { STRLEN off = vptr - (U8*)SvPVX(vsv); + vfree += vlen; vlen *= 2; SvGROW(vsv, vlen); vptr = (U8*)SvPVX(vsv) + off; } - do { - *--eptr = '0' + uv % 10; - } while (uv /= 10); - elen = (ebuf + sizeof ebuf) - eptr; memcpy(vptr, eptr, elen); vptr += elen; *vptr++ = '.'; + vfree -= elen + 1; vcur += elen + 1; } if (vcur) { |