SETs(TARG);
}
else {
+ STRLEN min = len + 1;
+
(void)SvUPGRADE(TARG, SVt_PV);
- SvGROW(TARG, len + 1);
+ SvGROW(TARG, min);
(void)SvPOK_only(TARG);
d = (U8*)SvPVX(TARG);
send = s + len;
STRLEN u = UTF8SKIP(s);
toUPPER_utf8(s, tmpbuf, &ulen);
- if (ulen > u) {
+ if (ulen > u && (SvLEN(TARG) < (min += ulen - u))) {
+ /* If the eventually required minimum size outgrows
+ * the available space, we need to grow. */
UV o = d - (U8*)SvPVX(TARG);
/* If someone uppercases one million U+03B0s we
* SvGROW() one million times. Or we could try
* guessing how much to allocate without allocating
* too much. Such is life. */
- SvGROW(TARG, SvLEN(TARG) + ulen - u);
+ SvGROW(TARG, min);
d = (U8*)SvPVX(TARG) + o;
}
Copy(tmpbuf, d, ulen, U8);
SETs(TARG);
}
else {
+ STRLEN min = len + 1;
+
(void)SvUPGRADE(TARG, SVt_PV);
- SvGROW(TARG, len + 1);
+ SvGROW(TARG, min);
(void)SvPOK_only(TARG);
d = (U8*)SvPVX(TARG);
send = s + len;
* See lib/unicore/SpecialCasing.txt.
*/
}
- if (ulen > u) {
+ if (ulen > u && (SvLEN(TARG) < (min += ulen - u))) {
+ /* If the eventually required minimum size outgrows
+ * the available space, we need to grow. */
UV o = d - (U8*)SvPVX(TARG);
/* If someone lowercases one million U+0130s we
* SvGROW() one million times. Or we could try
* guessing how much to allocate without allocating.
* too much. Such is life. */
- SvGROW(TARG, SvLEN(TARG) + ulen - u);
+ SvGROW(TARG, min);
d = (U8*)SvPVX(TARG) + o;
}
Copy(tmpbuf, d, ulen, U8);