crt: call __mingw_isleadbyte_cp from __mingw_mbrtowc_cp

Previously, `__mingw_mbrtowc_cp` called CRT's `isleadbyte` to determine
whether first byte pointed to by `mbs` is a DBCS leading byte.

While `__mingw_mbrtowc_cp` explicitly takes code page to operate on,
CRT's `isleadbyte` depends on active locale set with `setlocale`.

Using `__mingw_isleadbyte_cp` instead has the following advantages:

1. This removes dependency on CRT state, making it possible to call
`__mingw_mbrtowc_cp` with any SBCS and DBCS code page regardless of thread's
active locale.

2. This removes a possible race condition when either of `mbrlen`, `mbrtowc` or
`mbsrtowcs` obtained code page information from CRT, but then another thread
changed global locale before `__mingw_mbrtowc_cp` has called `isleadbyte`,
leading to incorrect results.

Signed-off-by: Kirill Makurin <maiddaisuki@outlook.com>
Signed-off-by: LIU Hao <lh_mouse@126.com>
1 file changed