summaryrefslogtreecommitdiff
path: root/toke.c
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2000-08-01 15:54:08 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2000-08-01 15:54:08 +0000
commitf72f5f8993f881ab1e0cb378ff33e0935207ff8c (patch)
treefb4fb4b74b386cc4e8b437acf4c05891e5499690 /toke.c
parent9422c00b50432b881d4068e835547b477a7bfcf5 (diff)
downloadperl-f72f5f8993f881ab1e0cb378ff33e0935207ff8c.tar.gz
BOM patching from Simon Cozens.
p4raw-id: //depot/perl@6478
Diffstat (limited to 'toke.c')
-rw-r--r--toke.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/toke.c b/toke.c
index 9d03733c88..777719f727 100644
--- a/toke.c
+++ b/toke.c
@@ -7386,8 +7386,8 @@ S_swallow_bom(pTHX_ U8 *s)
filter_add(utf16rev_textfilter, NULL);
New(898, news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
- PL_bufend = (char*)utf16_to_utf8(s, news,
- PL_bufend - (char*)s,
+ PL_bufend = (char*)utf16_to_utf8_reversed(s, news,
+ PL_bufend - (char*)s - 1,
&newlen);
Copy(news, s, newlen, U8);
SvCUR_set(PL_linestr, newlen);
@@ -7472,6 +7472,10 @@ utf16_textfilter(pTHXo_ int idx, SV *sv, int maxlen)
U8* tend;
I32 newlen;
New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8);
+ if (!*SvPV_nolen(sv))
+ /* Game over, but don't feed an odd-length string to utf16_to_utf8 */
+ return count;
+
tend = utf16_to_utf8((U8*)SvPVX(sv), tmps, SvCUR(sv), &newlen);
sv_usepvn(sv, (char*)tmps, tend - tmps);
}
@@ -7486,6 +7490,10 @@ utf16rev_textfilter(pTHXo_ int idx, SV *sv, int maxlen)
U8* tmps;
U8* tend;
I32 newlen;
+ if (!*SvPV_nolen(sv))
+ /* Game over, but don't feed an odd-length string to utf16_to_utf8 */
+ return count;
+
New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8);
tend = utf16_to_utf8_reversed((U8*)SvPVX(sv), tmps, SvCUR(sv), &newlen);
sv_usepvn(sv, (char*)tmps, tend - tmps);