summaryrefslogtreecommitdiff
path: root/sv.c
diff options
context:
space:
mode:
authorSADAHIRO Tomoyuki <BQW10602@nifty.com>2006-05-22 04:33:21 +0900
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2006-05-29 13:41:24 +0000
commitcc61b222958c07650542902d07ee4c04d4d76213 (patch)
tree8ef1802ae38b99f6820b17f84b1c757db13fc568 /sv.c
parentfa656879f58e30292c0192b81de3ede0e1d354d5 (diff)
downloadperl-cc61b222958c07650542902d07ee4c04d4d76213.tar.gz
Re: [perl #39126] possible memory related bug when using sprintf with an utf-8 encoded format-string and iso-8859-1 encoded string variables.
Message-Id: <20060521193259.81E5.BQW10602@nifty.com> with test tweaks further suggested by the same p4raw-id: //depot/perl@28328
Diffstat (limited to 'sv.c')
-rw-r--r--sv.c36
1 files changed, 19 insertions, 17 deletions
diff --git a/sv.c b/sv.c
index d6e307d583..3653b86652 100644
--- a/sv.c
+++ b/sv.c
@@ -9338,27 +9338,29 @@ Perl_sv_vcatpvfn(pTHX_ SV *sv, const char *pat, STRLEN patlen, va_list *args, SV
continue; /* not "break" */
}
- /* calculate width before utf8_upgrade changes it */
+ if (is_utf8 != has_utf8) {
+ if (is_utf8) {
+ if (SvCUR(sv))
+ sv_utf8_upgrade(sv);
+ }
+ else {
+ const STRLEN old_elen = elen;
+ SV * const nsv = sv_2mortal(newSVpvn(eptr, elen));
+ sv_utf8_upgrade(nsv);
+ eptr = SvPVX_const(nsv);
+ elen = SvCUR(nsv);
+
+ if (width) { /* fudge width (can't fudge elen) */
+ width += elen - old_elen;
+ }
+ is_utf8 = TRUE;
+ }
+ }
+
have = esignlen + zeros + elen;
if (have < zeros)
Perl_croak_nocontext(PL_memory_wrap);
- if (is_utf8 != has_utf8) {
- if (is_utf8) {
- if (SvCUR(sv))
- sv_utf8_upgrade(sv);
- }
- else {
- SV * const nsv = sv_2mortal(newSVpvn(eptr, elen));
- sv_utf8_upgrade(nsv);
- eptr = SvPVX_const(nsv);
- elen = SvCUR(nsv);
- }
- SvGROW(sv, SvCUR(sv) + elen + 1);
- p = SvEND(sv);
- *p = '\0';
- }
-
need = (have > width ? have : width);
gap = need - have;