Rebased onto current master.
From 9dff64a5101937c377575a5de7b446ef32f6b206 Mon Sep 17 00:00:00 2001 From: LIU Hao <[email protected]> Date: Sat, 1 Aug 2026 19:05:07 +0800 Subject: [PATCH] headers/stralign{,_s}: Fix implementations of `ua_wcs{cpy_s,chr,rchr}` Old code checked for `_WConst_Return` which is never defined; it is `_WConst_return` that is defined in corecrt.h, so these definitions were never compiled. And these definitions turn out to be incorrect: `ua_wcscpy_s` references non-existent parameters, and `ua_wcschr` calls `wcscpy`. These have to be re-implemented. It's worth noting that Microsoft stralign.h has also been having these typos since more than twenty years ago. Signed-off-by: LIU Hao <[email protected]> --- mingw-w64-headers/include/stralign.h | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/mingw-w64-headers/include/stralign.h b/mingw-w64-headers/include/stralign.h index 3e86b8ec2..ae3e1616a 100644 --- a/mingw-w64-headers/include/stralign.h +++ b/mingw-w64-headers/include/stralign.h @@ -109,9 +109,11 @@ extern "C" { PUWSTR_C ua_wcschr(PCUWSTR String,WCHAR Character); PUWSTR_C ua_wcsrchr(PCUWSTR String,WCHAR Character); -#if defined(__cplusplus) && defined(_WConst_Return) +#if defined(__cplusplus) && defined(_WConst_return) +extern "C++" { PUWSTR ua_wcschr(PUWSTR String,WCHAR Character); PUWSTR ua_wcsrchr(PUWSTR String,WCHAR Character); +} #endif PUWSTR ua_wcscpy(PUWSTR Destination,PCUWSTR Source); size_t ua_wcslen(PCUWSTR String); @@ -125,15 +127,17 @@ extern "C" { if(WSTR_ALIGNED(String)) return (PUWSTR_C)wcsrchr((PCWSTR)String,Character); return (PUWSTR_C)uaw_wcsrchr(String,Character); } -#if defined(__cplusplus) && defined(_WConst_Return) +#if defined(__cplusplus) && defined(_WConst_return) +extern "C++" { __CRT_INLINE PUWSTR ua_wcschr(PUWSTR String,WCHAR Character) { - if(WSTR_ALIGNED(String)) return wcscpy((PWSTR)Destination,(PCWSTR)Source); - return uaw_wcscpy(Destination,Source); + if(WSTR_ALIGNED(String)) return (PUWSTR)wcschr((PCWSTR)String,Character); + return (PUWSTR)uaw_wcschr(String,Character); } __CRT_INLINE PUWSTR ua_wcsrchr(PUWSTR String,WCHAR Character) { - if(WSTR_ALIGNED(String)) return wcsrchr(String,Character); - return uaw_wcsrchr((PCUWSTR)String,Character); + if(WSTR_ALIGNED(String)) return (PUWSTR)wcsrchr((PCWSTR)String,Character); + return (PUWSTR)uaw_wcsrchr(String,Character); } +} #endif __CRT_INLINE PUWSTR ua_wcscpy(PUWSTR Destination,PCUWSTR Source) { @@ -199,10 +203,10 @@ extern "C" { #endif #if !defined(_X86_) && defined(_WSTRING_S_DEFINED) -#if defined(__cplusplus) && defined(_WConst_Return) +#if defined(__cplusplus) && defined(_WConst_return) static __inline PUWSTR ua_wcscpy_s(PUWSTR Destination,size_t DestinationSize,PCUWSTR Source) {if(WSTR_ALIGNED(Source) && WSTR_ALIGNED(Destination)) return (wcscpy_s((PWSTR)Destination,DestinationSize,(PCWSTR)Source)==0 ? Destination : NULL);
- return uaw_wcscpy((PCUWSTR)String,Character); + return uaw_wcscpy((PWSTR)Destination,(PCWSTR)Source); } #endif #endif -- 2.55.0
From 9dff64a5101937c377575a5de7b446ef32f6b206 Mon Sep 17 00:00:00 2001 From: LIU Hao <[email protected]> Date: Sat, 1 Aug 2026 19:05:07 +0800 Subject: [PATCH] headers/stralign{,_s}: Fix implementations of `ua_wcs{cpy_s,chr,rchr}` Old code checked for `_WConst_Return` which is never defined; it is `_WConst_return` that is defined in corecrt.h, so these definitions were never compiled. And these definitions turn out to be incorrect: `ua_wcscpy_s` references non-existent parameters, and `ua_wcschr` calls `wcscpy`. These have to be re-implemented. It's worth noting that Microsoft stralign.h has also been having these typos since more than twenty years ago. Signed-off-by: LIU Hao <[email protected]> --- mingw-w64-headers/include/stralign.h | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/mingw-w64-headers/include/stralign.h b/mingw-w64-headers/include/stralign.h index 3e86b8ec2..ae3e1616a 100644 --- a/mingw-w64-headers/include/stralign.h +++ b/mingw-w64-headers/include/stralign.h @@ -109,9 +109,11 @@ extern "C" { PUWSTR_C ua_wcschr(PCUWSTR String,WCHAR Character); PUWSTR_C ua_wcsrchr(PCUWSTR String,WCHAR Character); -#if defined(__cplusplus) && defined(_WConst_Return) +#if defined(__cplusplus) && defined(_WConst_return) +extern "C++" { PUWSTR ua_wcschr(PUWSTR String,WCHAR Character); PUWSTR ua_wcsrchr(PUWSTR String,WCHAR Character); +} #endif PUWSTR ua_wcscpy(PUWSTR Destination,PCUWSTR Source); size_t ua_wcslen(PCUWSTR String); @@ -125,15 +127,17 @@ extern "C" { if(WSTR_ALIGNED(String)) return (PUWSTR_C)wcsrchr((PCWSTR)String,Character); return (PUWSTR_C)uaw_wcsrchr(String,Character); } -#if defined(__cplusplus) && defined(_WConst_Return) +#if defined(__cplusplus) && defined(_WConst_return) +extern "C++" { __CRT_INLINE PUWSTR ua_wcschr(PUWSTR String,WCHAR Character) { - if(WSTR_ALIGNED(String)) return wcscpy((PWSTR)Destination,(PCWSTR)Source); - return uaw_wcscpy(Destination,Source); + if(WSTR_ALIGNED(String)) return (PUWSTR)wcschr((PCWSTR)String,Character); + return (PUWSTR)uaw_wcschr(String,Character); } __CRT_INLINE PUWSTR ua_wcsrchr(PUWSTR String,WCHAR Character) { - if(WSTR_ALIGNED(String)) return wcsrchr(String,Character); - return uaw_wcsrchr((PCUWSTR)String,Character); + if(WSTR_ALIGNED(String)) return (PUWSTR)wcsrchr((PCWSTR)String,Character); + return (PUWSTR)uaw_wcsrchr(String,Character); } +} #endif __CRT_INLINE PUWSTR ua_wcscpy(PUWSTR Destination,PCUWSTR Source) { @@ -199,10 +203,10 @@ extern "C" { #endif #if !defined(_X86_) && defined(_WSTRING_S_DEFINED) -#if defined(__cplusplus) && defined(_WConst_Return) +#if defined(__cplusplus) && defined(_WConst_return) static __inline PUWSTR ua_wcscpy_s(PUWSTR Destination,size_t DestinationSize,PCUWSTR Source) { if(WSTR_ALIGNED(Source) && WSTR_ALIGNED(Destination)) return (wcscpy_s((PWSTR)Destination,DestinationSize,(PCWSTR)Source)==0 ? Destination : NULL); - return uaw_wcscpy((PCUWSTR)String,Character); + return uaw_wcscpy((PWSTR)Destination,(PCWSTR)Source); } #endif #endif -- 2.55.0
OpenPGP_signature.asc
Description: OpenPGP digital signature
_______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
