From 70a499f635a8f42bfdd9c719faa6ddbd05bf7d6a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 14 Apr 2017 19:00:44 +0200 Subject: [PATCH] Don't rely on argv being NULL-terminated under MSW Since the changes of c9a458bfe87445dd4042b50522d9e0fed1c2f694 ("Use Win32 ::CommandLineToArgvW() to tokenize command line"), this is not guaranteed any more as this Win32 function doesn't necessarily ensure it under older MSW versions such as XP. Just use "argc" explicitly instead of relying on this in wxCmdLineArgsArray to fix crashing under XP. --- include/wx/cmdargs.h | 10 ++++------ src/common/init.cpp | 3 +-- src/gtk/app.cpp | 2 +- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/include/wx/cmdargs.h b/include/wx/cmdargs.h index 257b091b18..6091730947 100644 --- a/include/wx/cmdargs.h +++ b/include/wx/cmdargs.h @@ -31,19 +31,17 @@ public: wxCmdLineArgsArray() { m_argsA = NULL; m_argsW = NULL; } template - wxCmdLineArgsArray& operator=(T **argv) + void Init(int argc, T **argv) { FreeArgs(); m_args.clear(); + m_args.reserve(argc); - if ( argv ) + for ( int i = 0; i < argc; i++ ) { - while ( *argv ) - m_args.push_back(*argv++); + m_args.push_back(argv[i]); } - - return *this; } operator char**() const diff --git a/src/common/init.cpp b/src/common/init.cpp index 5a3b521d0f..69af1e154d 100644 --- a/src/common/init.cpp +++ b/src/common/init.cpp @@ -335,8 +335,7 @@ bool wxEntryStart(int& argc, wxChar **argv) // remember, possibly modified (e.g. due to removal of toolkit-specific // parameters), command line arguments in member variables - app->argc = argc; - app->argv = argv; + app->argv.Init(argc, argv); wxCallAppCleanup callAppCleanup(app.get()); diff --git a/src/gtk/app.cpp b/src/gtk/app.cpp index f7124cefab..a27fc2aa82 100644 --- a/src/gtk/app.cpp +++ b/src/gtk/app.cpp @@ -396,7 +396,7 @@ bool wxApp::Initialize(int& argc_, wxChar **argv_) // update internal arg[cv] as GTK+ may have removed processed options: this->argc = argc_; - this->argv = argv_; + this->argv.Init(argc_, argv_); if ( m_traits ) {