const bool left_utf = DO_UTF8(left);
const bool right_utf = DO_UTF8(right);
I32 needlen = 0;
+ bool needfree = FALSE;
if (left_utf && !right_utf)
sv_utf8_upgrade(right);
rsave = rc = SvPV_nomg_const(right, rightlen);
len = leftlen < rightlen ? leftlen : rightlen;
lensave = len;
+ SvCUR_set(sv, len);
+ (void)SvPOK_only(sv);
if ((left_utf || right_utf) && (sv == left || sv == right)) {
needlen = optype == OP_BIT_AND ? len : leftlen + rightlen;
Newxz(dc, needlen + 1, char);
+ needfree = TRUE;
}
else if (SvOK(sv) || SvTYPE(sv) > SVt_PVMG) {
dc = SvPV_force_nomg_nolen(sv);
sv_usepvn_flags(sv, dc, needlen, SV_HAS_TRAILING_NUL);
dc = SvPVX(sv); /* sv_usepvn() calls Renew() */
}
- SvCUR_set(sv, len);
- (void)SvPOK_only(sv);
if (left_utf || right_utf) {
UV duc, luc, ruc;
char *dcorig = dc;
duc = luc & ruc;
dc = (char*)uvchr_to_utf8((U8*)dc, duc);
}
- if (sv == left || sv == right)
- (void)sv_usepvn(sv, dcorig, needlen);
+ if (sv == left || sv == right) {
+ (void)sv_usepvn(sv, dcorig, needlen); /* Uses Renew(). */
+ needfree = FALSE; /* sv_usepvn() moved dcorig. */
+ }
SvCUR_set(sv, dc - dcorig);
break;
case OP_BIT_XOR:
duc = luc | ruc;
dc = (char*)uvchr_to_utf8((U8*)dc, duc);
}
+ goto mop_up_utf; /* For consistency. */
mop_up_utf:
if (rulen)
dcsave = savepvn(rc, rulen);
else if (lulen)
dcsave = savepvn(lc, lulen);
- if (sv == left || sv == right)
+ if (sv == left || sv == right) {
(void)sv_usepvn(sv, dcorig, needlen); /* Uses Renew(). */
+ needfree = FALSE; /* sv_usepvn() moved dcorig. */
+ }
SvCUR_set(sv, dc - dcorig);
if (rulen)
sv_catpvn(sv, dcsave, rulen);
Safefree(dcsave);
break;
}
+ if (needfree)
+ Safefree(dcorig);
SvUTF8_on(sv);
goto finish;
}