If MultiByteToWideChar failed, it could still have overwritten
the output variable.

Signed-off-by: Martin Storsjö <[email protected]>
---
 mingw-w64-crt/misc/btowc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/mingw-w64-crt/misc/btowc.c b/mingw-w64-crt/misc/btowc.c
index 026b491d7..c8fbd8e74 100644
--- a/mingw-w64-crt/misc/btowc.c
+++ b/mingw-w64-crt/misc/btowc.c
@@ -19,8 +19,10 @@ wint_t btowc (int c)
     {
       unsigned char ch = c;
       wchar_t wc = WEOF;
-      MultiByteToWideChar (___lc_codepage_func(), MB_ERR_INVALID_CHARS,
-                          (char*)&ch, 1, &wc, 1);
+      if (!MultiByteToWideChar (___lc_codepage_func(), MB_ERR_INVALID_CHARS,
+                                (char*)&ch, 1, &wc, 1))
+        return WEOF;
+
       return wc;
     }
 }
-- 
2.25.1



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

Reply via email to