From 86fe598475b599d69100b28ed971bb38c3475916 Mon Sep 17 00:00:00 2001 From: Mattiwatti Date: Sat, 29 Jul 2017 05:53:47 +0200 Subject: [PATCH] Make the default command line the quoted image path, to prevent empty command lines in case no arguments were specified --- TitanEngine/TitanEngine.Debugger.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/TitanEngine/TitanEngine.Debugger.cpp b/TitanEngine/TitanEngine.Debugger.cpp index f7e3964..db861c8 100644 --- a/TitanEngine/TitanEngine.Debugger.cpp +++ b/TitanEngine/TitanEngine.Debugger.cpp @@ -215,15 +215,16 @@ __declspec(dllexport) void* TITCALL InitNativeDebugW(wchar_t* szFileName, wchar_ goto finished; // Convert command line and directory to UNICODE_STRING if present - SIZE_T ArgumentsLength = lstrlenW(szCommandLine); - if(szCommandLine != NULL && ArgumentsLength > 0) + SIZE_T ArgumentsLength = szCommandLine != NULL ? lstrlenW(szCommandLine) : 0; + SIZE_T BufferSize = ImagePath.Length + ((ArgumentsLength + 4) * sizeof(wchar_t)); + CommandLine.Buffer = (PWSTR)RtlAllocateHeap(RtlProcessHeap(), HEAP_ZERO_MEMORY, BufferSize * 10); + CommandLine.MaximumLength = (USHORT)BufferSize; + RtlAppendUnicodeToString(&CommandLine, L"\""); + RtlAppendUnicodeStringToString(&CommandLine, &ImagePath); + RtlAppendUnicodeToString(&CommandLine, L"\""); + if(ArgumentsLength > 0) { - SIZE_T BufferSize = ImagePath.Length + ((ArgumentsLength + 4) * sizeof(wchar_t)); - CommandLine.Buffer = (PWSTR)RtlAllocateHeap(RtlProcessHeap(), HEAP_ZERO_MEMORY, BufferSize); - CommandLine.MaximumLength = (USHORT)BufferSize; - RtlAppendUnicodeToString(&CommandLine, L"\""); - RtlAppendUnicodeStringToString(&CommandLine, &ImagePath); - RtlAppendUnicodeToString(&CommandLine, L"\" "); + RtlAppendUnicodeToString(&CommandLine, L" "); RtlAppendUnicodeToString(&CommandLine, szCommandLine); }