DEVEL15-windows-license-smgl2rtf-20090105

LICENSE MIT

Ensure that the input string is nul terminated and then instruct
WideCharToMultiByte to compute the length itself instead of passing
in a value that is very likely to be wrong.


(cherry picked from commit e7edfbbf2204641ba08d0ae5e0d085e5f913f2d2)
This commit is contained in:
Jeffrey Altman 2009-01-05 18:17:01 +00:00
parent 0ebd363f1a
commit d97ef4b087

View File

@ -216,8 +216,8 @@ BOOL TranslateFile (LPTSTR psz)
DWORD cbSource;
if ((cbSource = GetFileSize (hFile, NULL)) != 0)
{
LPTSTR abSource = (LPTSTR)malloc(cbSource + 1);
memset(abSource, 0x00, cbSource + 1);
LPTSTR abSource = (LPTSTR)malloc(cbSource + 4);
memset(abSource, 0x00, cbSource + 4);
DWORD dwRead;
if (!ReadFile (hFile, abSource, cbSource, &dwRead, NULL) || cbSource != dwRead)
@ -232,7 +232,7 @@ BOOL TranslateFile (LPTSTR psz)
memset (abTarget, 0x00, cbTarget);
BOOL fDefault = FALSE;
WideCharToMultiByte (g::CodePage, 0, (LPCWSTR)abSource, cbSource, abTarget, cbTarget, TEXT(" "), &fDefault);
WideCharToMultiByte (g::CodePage, 0, (LPCWSTR)abSource, -1, abTarget, cbTarget, TEXT(" "), &fDefault);
rc = FormatFile (psz, abTarget);