mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 14:38:18 +00:00
Use assertions in CWindowsConsoleLogger
instead of error messages
The function `MultiByteToWideChar` can't fail unless wrong arguments are passed, when the buffer size is set correctly by calling the function twice. The returned buffer size on the second call should always match the buffer size determined with the first call.
This commit is contained in:
parent
203fb97eae
commit
f74797ae0c
|
@ -339,21 +339,9 @@ public:
|
|||
void Log(const CLogMessage *pMessage) override
|
||||
{
|
||||
int WLen = MultiByteToWideChar(CP_UTF8, 0, pMessage->m_aLine, pMessage->m_LineLength, NULL, 0);
|
||||
if(!WLen)
|
||||
{
|
||||
WCHAR aError[] = L"Failed to obtain length of log message\r\n";
|
||||
WriteConsoleW(m_pConsole, aError, std::size(aError) - 1, NULL, NULL);
|
||||
return;
|
||||
}
|
||||
dbg_assert(WLen > 0, "MultiByteToWideChar failure");
|
||||
WCHAR *pWide = (WCHAR *)malloc((WLen + 2) * sizeof(*pWide));
|
||||
WLen = MultiByteToWideChar(CP_UTF8, 0, pMessage->m_aLine, pMessage->m_LineLength, pWide, WLen);
|
||||
if(!WLen)
|
||||
{
|
||||
WCHAR aError[] = L"Failed to convert log message encoding\r\n";
|
||||
WriteConsoleW(m_pConsole, aError, std::size(aError) - 1, NULL, NULL);
|
||||
free(pWide);
|
||||
return;
|
||||
}
|
||||
dbg_assert(MultiByteToWideChar(CP_UTF8, 0, pMessage->m_aLine, pMessage->m_LineLength, pWide, WLen) == WLen, "MultiByteToWideChar failure");
|
||||
pWide[WLen++] = '\r';
|
||||
pWide[WLen++] = '\n';
|
||||
|
||||
|
|
Loading…
Reference in a new issue