Skip to content

Commit

Permalink
Fix what() ERROR_INSUFFICIENT_BUFFER, fix nullptr (#381)
Browse files Browse the repository at this point in the history
Co-authored-by: Duncan Horn <[email protected]>
  • Loading branch information
m417z and dunhor authored Oct 24, 2023
1 parent 6732119 commit 5e9be7b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions include/wil/result_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -2574,9 +2574,14 @@ __WI_POP_WARNINGS
wchar_t message[2048];
GetFailureLogString(message, ARRAYSIZE(message), m_failure.GetFailureInfo());

char messageA[1024];
int len = WideCharToMultiByte(CP_ACP, 0, message, -1, messageA, ARRAYSIZE(messageA), nullptr, nullptr);
m_what.create(messageA, len);
int len = WideCharToMultiByte(CP_ACP, 0, message, -1, nullptr, 0, nullptr, nullptr);
if (!m_what.create(len))
{
// Allocation failed, return placeholder string.
return "WIL Exception";
}

WideCharToMultiByte(CP_ACP, 0, message, -1, static_cast<char *>(m_what.get()), len, nullptr, nullptr);
}
return static_cast<const char *>(m_what.get());
}
Expand Down

0 comments on commit 5e9be7b

Please sign in to comment.