summaryrefslogtreecommitdiff
path: root/locale.c
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2017-09-11 17:32:42 -0600
committerKarl Williamson <khw@cpan.org>2017-11-08 20:52:52 -0700
commit51fc4b19eb5af1211f960bc49d322c020490bc61 (patch)
tree7990abd0a9a52e0dbbe04c1b6afb12137cef1fed /locale.c
parentff1b739b7e749b9f4005279ddb782cb23a2322a9 (diff)
downloadperl-51fc4b19eb5af1211f960bc49d322c020490bc61.tar.gz
locale.c: Avoid extra call to mbtowc()
This is done only when debugging, but in some locales that have shift states, the extra call could blow up. Instead save the result of the mbtowc() call we care about.
Diffstat (limited to 'locale.c')
-rw-r--r--locale.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/locale.c b/locale.c
index 3d689587eb..d04fb66c23 100644
--- a/locale.c
+++ b/locale.c
@@ -3055,17 +3055,20 @@ Perl__is_cur_LC_category_utf8(pTHX_ int category)
* result */
if (is_utf8) {
wchar_t wc;
+ int len;
+
PERL_UNUSED_RESULT(mbtowc(&wc, NULL, 0));/* Reset any shift state */
errno = 0;
- if ((size_t)mbtowc(&wc, HYPHEN_UTF8, strlen(HYPHEN_UTF8))
- != strlen(HYPHEN_UTF8)
+ len = mbtowc(&wc, STR_WITH_LEN(HYPHEN_UTF8));
+
+ if ( len != STRLENs(HYPHEN_UTF8)
|| wc != (wchar_t) 0x2010)
{
is_utf8 = FALSE;
DEBUG_L(PerlIO_printf(Perl_debug_log, "\thyphen=U+%x\n", (unsigned int)wc));
DEBUG_L(PerlIO_printf(Perl_debug_log,
"\treturn from mbtowc=%d; errno=%d; ?UTF8 locale=0\n",
- mbtowc(&wc, HYPHEN_UTF8, strlen(HYPHEN_UTF8)), errno));
+ len, errno));
}
}