Skip to content

Commit f177882

Browse files
committed
do_chomp: Use utf8_to_bytes_new_pv()
1 parent a015052 commit f177882

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

pp.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ S_do_chomp(pTHX_ SV *retval, SV *sv, bool chomping)
793793
s = SvPV(sv, len);
794794
if (chomping) {
795795
if (s && len) {
796-
char *temp_buffer = NULL;
796+
U8 *temp_buffer = NULL;
797797
s += --len;
798798
if (RsPARA(PL_rs)) {
799799
if (*s != '\n')
@@ -817,23 +817,18 @@ S_do_chomp(pTHX_ SV *retval, SV *sv, bool chomping)
817817
/* Assumption is that rs is shorter than the scalar. */
818818
if (SvUTF8(PL_rs)) {
819819
/* RS is utf8, scalar is 8 bit. */
820-
bool is_utf8 = TRUE;
821-
temp_buffer = (char*)bytes_from_utf8((U8*)rsptr,
822-
&rslen, &is_utf8);
823-
if (is_utf8) {
824-
/* Cannot downgrade, therefore cannot possibly match.
825-
At this point, temp_buffer is not alloced, and
826-
is the buffer inside PL_rs, so don't free it.
827-
*/
828-
assert (temp_buffer == rsptr);
820+
if (! utf8_to_bytes_new_pv(&rsptr, &rslen,
821+
&temp_buffer))
822+
{
823+
/* Cannot downgrade, therefore cannot possibly
824+
* match. */
829825
goto nope_free_nothing;
830826
}
831-
rsptr = temp_buffer;
832827
}
833828
else {
834829
/* RS is 8 bit, scalar is utf8. */
835-
temp_buffer = (char*)bytes_to_utf8((U8*)rsptr, &rslen);
836-
rsptr = temp_buffer;
830+
temp_buffer = bytes_to_utf8((U8*)rsptr, &rslen);
831+
rsptr = (char *) temp_buffer;
837832
}
838833
}
839834
if (rslen == 1) {

0 commit comments

Comments
 (0)