Thank you for testing. This happens which I write test which passing
under UCRT and then I modify & extend it for msvcrt functionality.
On Saturday 13 September 2025 00:35:43 Martin Storsjö wrote:
> On Sun, 31 Aug 2025, Pali Rohár wrote:
>
> > ---
> > mingw-w64-crt/testcases/Makefile.am | 1 +
> > mingw-w64-crt/testcases/t_wcstok_s.c | 101 +++++++++++++++++++++++++++
> > 2 files changed, 102 insertions(+)
> > create mode 100644 mingw-w64-crt/testcases/t_wcstok_s.c
>
> This testcase fails in many configurations.
>
> On UCRT (on all architectures), it only produces this output:
>
> FAIL: t_wcstok_s
> ================
>
> FAIL t_wcstok_s.exe (exit status: 139)
Ou. I see. The second test case is crashing inside the UCRT's wcstok()
function. So there is no assert output and because of crash there is
also no other visible output. Normally dr watson would be visible.
After debugging, it looks like that UCRT's wcstok() function does not
accept NULL state when the string is NULL. And is trying to dereference
the *state (which cause NULL dereference and crash). I would propose to
disable the second test case. With that change, the test passed my tests
under UCRT env.
diff --git a/mingw-w64-crt/testcases/t_wcstok_s.c
b/mingw-w64-crt/testcases/t_wcstok_s.c
index a9ce9f3dc9d8..ff02805bd1e6 100644
--- a/mingw-w64-crt/testcases/t_wcstok_s.c
+++ b/mingw-w64-crt/testcases/t_wcstok_s.c
@@ -36,7 +36,9 @@ int main() {
assert(handler_called == 0);
assert(handler_errno == -1);
- /* wcstok for NULL string and state returns NULL and does not set errno
and does not call handler */
+ /* msvcrt wcstok for NULL string and state returns NULL and does not set
errno and does not call handler */
+ /* UCRT wcstok for NULL string expects that the state is non-NULL and
dereference it, so do not call this test for UCRT */
+#ifndef _UCRT
handler_called = 0;
handler_errno = -1;
errno = -1;
@@ -46,6 +48,7 @@ int main() {
assert(errno == -1);
assert(handler_called == 0);
assert(handler_errno == -1);
+#endif
/* wcstok_s normal usage without errors */
handler_called = 0;
>
> On msvcrt, on aarch64 and arm64ec (armv7 untested), it fails like this:
>
> FAIL: t_wcstok_s
> ================
>
> Assertion failed: handler_called == 1, file ../../testcases/t_wcstok_s.c,
> line 75
> FAIL t_wcstok_s.exe (exit status: 3)
This looks like that msvcrt.dll's wcstok_s on all platforms is calling
msvcrt.dll's _invalid_parameter which is broken. So the registered
exception handler is not called at all.
Replacing wcstok_s by mingw-w64 emulation also on arm platforms (not
just i386 and x64) could help here. Could you check this change?
diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am
index 20c6f4ffa09b..904a485a642d 100644
--- a/mingw-w64-crt/Makefile.am
+++ b/mingw-w64-crt/Makefile.am
@@ -374,6 +374,7 @@ src_msvcrt=\
secapi/_vscprintf_p.c \
secapi/_vscwprintf_p.c \
secapi/_vswprintf_p.c \
+ secapi/wcstok_s.c \
secapi/wmemcpy_s.c \
secapi/wmemmove_s.c \
stdio/_ftelli64.c \
@@ -646,7 +647,6 @@ src_msvcrt32=\
misc/wcsnlen.c \
misc/wcstoimax.c \
misc/wcstoumax.c \
- secapi/wcstok_s.c \
stdio/_fseeki64.c \
stdio/_fstat64.c \
stdio/_fstat64i32.c \
@@ -707,7 +707,6 @@ src_msvcrt64=\
misc/strnlen.c \
misc/wassert.c \
misc/wcsnlen.c \
- secapi/wcstok_s.c \
stdio/_fseeki64.c \
stdio/_fstat32.c \
stdio/_fstat32i64.c \
diff --git a/mingw-w64-crt/lib-common/msvcrt.def.in
b/mingw-w64-crt/lib-common/msvcrt.def.in
index 4786924b53f4..2eee6389e04b 100644
--- a/mingw-w64-crt/lib-common/msvcrt.def.in
+++ b/mingw-w64-crt/lib-common/msvcrt.def.in
@@ -1847,7 +1847,7 @@ wcsncpy_s
F_ARM_ANY(wcsnlen) ; i386 and x64 wcsnlen replaced by emu
; wcsrtombs replaced by emu, CRT version does not report invalid conversion
state
wcsrtombs_s
-F_ARM_ANY(wcstok_s) ; i386 and x64 wcstok_s replaced by emu
+; wcstok_s replaced by emu, it does not call exception handler for invalid
arguments
wcstombs_s
; wctob replaced by emu, CRT version may sign-extend its return value
wctomb_s
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public