在 2026-6-24 15:35, Yonggang Luo 写道:
## Problem

After commit c85d64d8c ("crt: Add support for C95 (v)swprintf() functions
when __USE_MINGW_ANSI_STDIO=1"), swprintf(buf, n, ...) returns -1 when
the formatted output exactly fills n - 1 wide characters (plus the
terminator), even though ISO C95+ requires -1 only when n or more data
wide characters are needed.


diff --git a/mingw-w64-crt/testcases/t_swprintf_tmpl.h 
b/mingw-w64-crt/testcases/t_swprintf_tmpl.h
index a12cba9a2..5fe332645 100644
--- a/mingw-w64-crt/testcases/t_swprintf_tmpl.h
+++ b/mingw-w64-crt/testcases/t_swprintf_tmpl.h
@@ -19,5 +19,23 @@ int main() {
      fprintf(stderr, "\n");
      return 1;
    }
+
+  /* ISO C95+: output of 9 wide chars plus terminator must succeed when n=10.
+   * Regression for __mingw_vswprintf exact-fit check (retval == n-1). */
+  {
+    wchar_t exact[16] = L"XXXXXXXXXXXXXXXX";

While initializing an array without a null terminator this way is perfectly fine in standard C, GCC can warn about it:

warning: initializer-string for array of 'short unsigned int' truncates NUL terminator but destination lacks 'nonstring' attribute (34 chars into 32 available) [-Wunterminated-string-initialization]
      12 |     wchar_t exact[16] = L"XXXXXXXXXXXXXXXX";
         |                         ^~~~~~~~~~~~~~~~~~~

So I have to delete one X from the initializer.

The other change looks good. Fixed and pushed now. Thanks.



--
Best regards,
LIU Hao

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to