for (t = ustrp, tend = t + *lenp; t < tend; t += tlen) {
UV c = utf8_to_uvchr(t, &tlen);
- d = uvchr_to_utf8(d, UNI_TO_NATIVE(c));
+
+ if (tlen > 0)
+ d = uvchr_to_utf8(d, UNI_TO_NATIVE(c));
+ else
+ break;
}
*lenp = d - tmpbuf;
Copy(tmpbuf, ustrp, *lenp, U8);
}
/* isPRINT() is the locale-blind version. */
if (!ok && (flags & UNI_DISPLAY_ISPRINT) && isPRINT(u & 0xFF)) {
- Perl_sv_catpvf(aTHX_ dsv, "%c", u);
+ Perl_sv_catpvf(aTHX_ dsv, "%c", (char)(u & 0xFF));
ok = TRUE;
}
}