From 3fbd537371590e5d04dfa4f7bdaba14e6e59aa86 Mon Sep 17 00:00:00 2001 From: Jay Satiro Date: Sun, 30 Jul 2017 02:50:10 -0400 Subject: [PATCH] Fix command line argument parsing regression Work with the arguments in a temporary array of pointers to the command line before assigning them to paramVector as generic_string. Follow up to afb3889. Since then the arguments were copied to paramVector as generic_string too early, before the command line parsing finished. Closes https://github.com/notepad-plus-plus/notepad-plus-plus/pull/3575 --- PowerEditor/src/winmain.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/PowerEditor/src/winmain.cpp b/PowerEditor/src/winmain.cpp index 84c8b7eb..38d6030b 100644 --- a/PowerEditor/src/winmain.cpp +++ b/PowerEditor/src/winmain.cpp @@ -141,8 +141,8 @@ void parseCommandLine(const TCHAR* commandLine, ParamVector& paramVector) } bool isInFile = false; bool isInWhiteSpace = true; - paramVector.clear(); size_t commandLength = lstrlen(cmdLinePtr); + std::vector args; for (size_t i = 0; i < commandLength; ++i) { switch(cmdLinePtr[i]) @@ -151,7 +151,7 @@ void parseCommandLine(const TCHAR* commandLine, ParamVector& paramVector) { if (!isInFile) //" will always be treated as start or end of param, in case the user forgot to add an space { - paramVector.push_back(cmdLinePtr+i+1); //add next param(since zero terminated generic_string original, no overflow of +1) + args.push_back(cmdLinePtr+i+1); //add next param(since zero terminated original, no overflow of +1) } isInFile = !isInFile; isInWhiteSpace = false; @@ -173,14 +173,13 @@ void parseCommandLine(const TCHAR* commandLine, ParamVector& paramVector) { if (!isInFile && isInWhiteSpace) { - paramVector.push_back(cmdLinePtr+i); //add next param + args.push_back(cmdLinePtr+i); //add next param isInWhiteSpace = false; } } } } - //the commandline generic_string is now a list of zero terminated strings concatenated, and the vector contains all the substrings - + paramVector.assign(args.begin(), args.end()); delete [] cmdLine; }