Skip to content

Commit 5e9be7b

Browse files
m417zdunhor
andauthored
Fix what() ERROR_INSUFFICIENT_BUFFER, fix nullptr (#381)
Co-authored-by: Duncan Horn <[email protected]>
1 parent 6732119 commit 5e9be7b

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

include/wil/result_macros.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2574,9 +2574,14 @@ __WI_POP_WARNINGS
25742574
wchar_t message[2048];
25752575
GetFailureLogString(message, ARRAYSIZE(message), m_failure.GetFailureInfo());
25762576

2577-
char messageA[1024];
2578-
int len = WideCharToMultiByte(CP_ACP, 0, message, -1, messageA, ARRAYSIZE(messageA), nullptr, nullptr);
2579-
m_what.create(messageA, len);
2577+
int len = WideCharToMultiByte(CP_ACP, 0, message, -1, nullptr, 0, nullptr, nullptr);
2578+
if (!m_what.create(len))
2579+
{
2580+
// Allocation failed, return placeholder string.
2581+
return "WIL Exception";
2582+
}
2583+
2584+
WideCharToMultiByte(CP_ACP, 0, message, -1, static_cast<char *>(m_what.get()), len, nullptr, nullptr);
25802585
}
25812586
return static_cast<const char *>(m_what.get());
25822587
}

0 commit comments

Comments
 (0)