Skip to content

Commit 4a9e05c

Browse files
committed
pp_syswrite: Use new utf8_to_bytes_temp_pv()
I considered using utf8_to_bytes_new_pv() and retaining all the free calls, but it seemed to me that it is brittle to have so many code paths that this could leak from, and whatever overhead a SAVEFREEPV() might add is dwarded by the syswrite.
1 parent e9e7ac5 commit 4a9e05c

File tree

1 file changed

+2
-13
lines changed

1 file changed

+2
-13
lines changed

pp_sys.c

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2191,7 +2191,6 @@ PP_wrapped(pp_syswrite, 0, 1)
21912191
STRLEN blen;
21922192
const int op_type = PL_op->op_type;
21932193
bool doing_utf8;
2194-
U8 *tmpbuf = NULL;
21952194
GV *const gv = MUTABLE_GV(*++MARK);
21962195
IO *const io = GvIO(gv);
21972196
int fd;
@@ -2242,15 +2241,10 @@ PP_wrapped(pp_syswrite, 0, 1)
22422241
OP_DESC(PL_op));
22432242
}
22442243
else if (doing_utf8) {
2245-
STRLEN tmplen = blen;
2246-
U8 * const result = bytes_from_utf8((const U8*) buffer, &tmplen, &doing_utf8);
2247-
if (!doing_utf8) {
2248-
tmpbuf = result;
2249-
buffer = (char *) tmpbuf;
2250-
blen = tmplen;
2244+
if (utf8_to_bytes_temp_pv((const U8**)&buffer, &blen)) {
2245+
doing_utf8 = false;
22512246
}
22522247
else {
2253-
assert((char *)result == buffer);
22542248
Perl_croak(aTHX_ "Wide character in %s", OP_DESC(PL_op));
22552249
}
22562250
}
@@ -2283,7 +2277,6 @@ PP_wrapped(pp_syswrite, 0, 1)
22832277
length = (Size_t)SvIVx(*++MARK);
22842278
#endif
22852279
if ((SSize_t)length < 0) {
2286-
Safefree(tmpbuf);
22872280
DIE(aTHX_ "Negative length");
22882281
}
22892282
}
@@ -2292,12 +2285,10 @@ PP_wrapped(pp_syswrite, 0, 1)
22922285
offset = SvIVx(*++MARK);
22932286
if (offset < 0) {
22942287
if (-offset > (IV)blen) {
2295-
Safefree(tmpbuf);
22962288
DIE(aTHX_ "Offset outside string");
22972289
}
22982290
offset += blen;
22992291
} else if (offset > (IV)blen) {
2300-
Safefree(tmpbuf);
23012292
DIE(aTHX_ "Offset outside string");
23022293
}
23032294
} else
@@ -2322,7 +2313,6 @@ PP_wrapped(pp_syswrite, 0, 1)
23222313
goto say_undef;
23232314
SP = ORIGMARK;
23242315

2325-
Safefree(tmpbuf);
23262316
#if Size_t_size > IVSIZE
23272317
PUSHn(retval);
23282318
#else
@@ -2331,7 +2321,6 @@ PP_wrapped(pp_syswrite, 0, 1)
23312321
RETURN;
23322322

23332323
say_undef:
2334-
Safefree(tmpbuf);
23352324
SP = ORIGMARK;
23362325
RETPUSHUNDEF;
23372326
}

0 commit comments

Comments
 (0)