From 7da9604e5c6aa224eb714ec4cfdccc8f0cf1fdc3 Mon Sep 17 00:00:00 2001 From: Kolan Sh Date: Tue, 25 Oct 2016 22:30:45 +0300 Subject: [PATCH] Ticket #10440: argv modification leads to runtime error with msvc 2015, so copy them. --- src/LyX.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/LyX.cpp b/src/LyX.cpp index d2484d1..ea8a096 100644 --- a/src/LyX.cpp +++ b/src/LyX.cpp @@ -287,9 +287,13 @@ int LyX::exec(int & argc, char * argv[]) LYXERR(Debug::LOCALE, message.title_ + ", " + message.details_); } + // Bug #10440: argv modification leads to runtime error with msvc 2015, so copy them + char ** argv_local = new char * [argc + 1]; + memcpy (argv_local, argv, (argc + 1) * sizeof (char *)); + // Here we need to parse the command line. At least // we need to parse for "-dbg" and "-help" - easyParse(argc, argv); + easyParse(argc, argv_local); try { init_package(os::utf8_argv(0), cl_system_support, cl_user_support); @@ -307,7 +311,7 @@ int LyX::exec(int & argc, char * argv[]) setLocale(); if (!use_gui) { - LyXConsoleApp app(this, argc, argv); + LyXConsoleApp app(this, argc, argv_local); // Reestablish our defaults, as Qt overwrites them // after creating app @@ -317,7 +321,7 @@ int LyX::exec(int & argc, char * argv[]) } // Let the frontend parse and remove all arguments that it knows - pimpl_->application_.reset(createApplication(argc, argv)); + pimpl_->application_.reset(createApplication(argc, argv_local)); // Reestablish our defaults, as Qt overwrites them // after createApplication() @@ -325,7 +329,10 @@ int LyX::exec(int & argc, char * argv[]) // Parse and remove all known arguments in the LyX singleton // Give an error for all remaining ones. - int exit_status = init(argc, argv); + int exit_status = init(argc, argv_local); + + delete [] argv_local; + if (exit_status) { // Kill the application object before exiting. pimpl_->application_.reset(); -- 2.7.3