mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 18:15:11 +00:00
[NTVDM]: Use variable-length buffers in DisplayMessage, in case we display a very long message (uses the _vscwprintf CRT function, not available on Win2k. You need to recompile NTVDM with WIN2K_COMPLIANT define if you want to be able to run it on win2k. In that case DisplayMessage uses a quite large enough buffer for its needs). If somebody knows an alternative to _vscwprintf that does the very same job, and which exists on Win2k, I would be happy to use it instead.
svn path=/trunk/; revision=65336
This commit is contained in:
parent
0a21e7b198
commit
a36ff01e00
1 changed files with 38 additions and 3 deletions
|
@ -185,13 +185,48 @@ static VOID ShowHideMousePointer(HANDLE ConOutHandle, BOOLEAN ShowPtr)
|
|||
VOID
|
||||
DisplayMessage(LPCWSTR Format, ...)
|
||||
{
|
||||
WCHAR Buffer[256];
|
||||
#ifndef WIN2K_COMPLIANT
|
||||
WCHAR StaticBuffer[256];
|
||||
LPWSTR Buffer = StaticBuffer; // Use the static buffer by default.
|
||||
#else
|
||||
WCHAR Buffer[2048]; // Large enough. If not, increase it by hand.
|
||||
#endif
|
||||
size_t MsgLen;
|
||||
va_list Parameters;
|
||||
|
||||
va_start(Parameters, Format);
|
||||
_vsnwprintf(Buffer, 256, Format, Parameters);
|
||||
|
||||
#ifndef WIN2K_COMPLIANT
|
||||
/*
|
||||
* Retrieve the message length and if it is too long, allocate
|
||||
* an auxiliary buffer; otherwise use the static buffer.
|
||||
*/
|
||||
MsgLen = _vscwprintf(Format, Parameters) + 1; // NULL-terminated
|
||||
if (MsgLen > sizeof(StaticBuffer)/sizeof(StaticBuffer[0]))
|
||||
{
|
||||
Buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, MsgLen * sizeof(WCHAR));
|
||||
if (Buffer == NULL)
|
||||
{
|
||||
/* Allocation failed, use the static buffer and display a suitable error message */
|
||||
Buffer = StaticBuffer;
|
||||
Format = L"DisplayMessage()\nOriginal message is too long and allocating an auxiliary buffer failed.";
|
||||
MsgLen = wcslen(Format);
|
||||
}
|
||||
}
|
||||
#else
|
||||
MsgLen = sizeof(Buffer)/sizeof(Buffer[0]);
|
||||
#endif
|
||||
|
||||
/* Display the message */
|
||||
_vsnwprintf(Buffer, MsgLen, Format, Parameters);
|
||||
DPRINT1("\n\nNTVDM Subsystem\n%S\n\n", Buffer);
|
||||
MessageBoxW(NULL, Buffer, L"NTVDM Subsystem", MB_OK);
|
||||
|
||||
#ifndef WIN2K_COMPLIANT
|
||||
/* Free the buffer if needed */
|
||||
if (Buffer != StaticBuffer) HeapFree(GetProcessHeap(), 0, Buffer);
|
||||
#endif
|
||||
|
||||
va_end(Parameters);
|
||||
}
|
||||
|
||||
|
@ -205,8 +240,8 @@ ConsoleCtrlHandler(DWORD ControlType)
|
|||
case CTRL_BREAK_EVENT:
|
||||
{
|
||||
/* HACK: Stop the VDM */
|
||||
DPRINT1("Ctrl-C/Break: Stop the VDM\n");
|
||||
EmulatorTerminate();
|
||||
|
||||
break;
|
||||
}
|
||||
case CTRL_LAST_CLOSE_EVENT:
|
||||
|
|
Loading…
Reference in a new issue