Skip to content

Commit

Permalink
crt: Check the return value from MultiByteToWideChar in btowc
Browse files Browse the repository at this point in the history
If MultiByteToWideChar failed, it could still have overwritten
the output variable.

Signed-off-by: Martin Storsjö <martin@martin.st>
  • Loading branch information
mstorsjo committed Feb 17, 2022
1 parent 2f6d8b8 commit 707c3b8
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions mingw-w64-crt/misc/btowc.c
Expand Up @@ -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;
}
}

0 comments on commit 707c3b8

Please sign in to comment.