]> git.lyx.org Git - features.git/commitdiff
Avoid an assertion when compiling in debug mode with MSVC 2015
authorEnrico Forestieri <forenr@lyx.org>
Wed, 12 Apr 2017 19:19:42 +0000 (21:19 +0200)
committerEnrico Forestieri <forenr@lyx.org>
Wed, 12 Apr 2017 19:19:42 +0000 (21:19 +0200)
Seemingly, when removing an argument from argv, and thus inserting
a null pointer to shorten the array, causes an assertion because
the null pointer is not a valid heap pointer (sic!)

Fixes bug #10440

src/main.cpp
src/support/os.h
src/support/os_cygwin.cpp
src/support/os_unix.cpp
src/support/os_win32.cpp
src/tex2lyx/tex2lyx.cpp

index b72725372be83e04874a17570fae7441fc19ef84..5c4fb468459dbc3fa2a7ab12bbf418d1b6f7674e 100644 (file)
@@ -35,7 +35,7 @@ int main(int argc, char * argv[])
        // early as possible.
        lyx::lyxerr.setStream(cerr);
 
-       lyx::support::os::init(argc, argv);
+       lyx::support::os::init(argc, &argv);
 
        lyx::LyX the_lyx_instance;
 
index 73eb86d7f331c51853fb5e972d5cb9cea038d6f5..9b38e4e44ee0272de8b5caf9be74e195ccc6ec5a 100644 (file)
@@ -38,7 +38,7 @@ enum file_access {
 };
 
 /// Do some work just once.
-void init(int argc, char * argv[]);
+void init(int argc, char ** argv[]);
 
 /// Returns the i-th program argument in utf8 encoding.
 std::string utf8_argv(int i);
index 702d67f4185b95cb7576f9db6b3982e46eb3edd5..1de0da6ef195c50c58d6b2a7964c09ce9867b832 100644 (file)
@@ -210,10 +210,10 @@ BOOL terminate_handler(DWORD event)
 
 } // namespace anon
 
-void init(int argc, char * argv[])
+void init(int argc, char ** argv[])
 {
        argc_ = argc;
-       argv_ = argv;
+       argv_ = *argv;
 
        // Set environment's default locale
        setlocale(LC_ALL, "");
index 230dab5aa953a4d893af6e02ff665cc58d24f7e3..135d3149916eb597ac18fd6b5a06e0cfefd1efe2 100644 (file)
@@ -45,10 +45,10 @@ char ** argv_ = 0;
 
 } // namespace anon
 
-void init(int argc, char * argv[])
+void init(int argc, char ** argv[])
 {
        argc_ = argc;
-       argv_ = argv;
+       argv_ = *argv;
 
        // Set environment's default locale
        setlocale(LC_ALL, "");
index a5b5bbe825cbe79c1da55fc3a8110de7bb851199..9078f594d747c6c8b17e8326382acf14548ef985 100644 (file)
@@ -99,7 +99,7 @@ BOOL terminate_handler(DWORD event)
 
 } // namespace anon
 
-void init(int argc, char * argv[])
+void init(int argc, char ** argv[])
 {
        /* Note from Angus, 17 Jan 2005:
         *
@@ -158,6 +158,22 @@ void init(int argc, char * argv[])
         */
 
 
+#if defined(_MSC_VER) && (_MSC_VER >= 1900)
+       // Removing an argument from argv leads to an assertion on Windows
+       // when compiling with MSVC 2015 in debug mode (see bug #10440).
+       // To avoid this we make a copy of the array of pointers.
+       char ** newargv = (char **) malloc((argc + 1) * sizeof(char *));
+       if (newargv) {
+               memcpy(newargv, *argv, (argc + 1) * sizeof(char *));
+               *argv = newargv;
+       } else {
+               lyxerr << "LyX warning: Cannot make a copy of "
+                         "command line arguments!"
+                      << endl;
+       }
+#endif
+
+
        // Get the wide program arguments array
 #if defined(_MSC_VER) && (_MSC_VER >= 1900)
        argv_ = CommandLineToArgvW(GetCommandLineW(), &argc_);
index 3f6fe73821431b688d6d9e82cb0ea9416dc03280..65a2b91ea2f0d90ba82376f1f718d91f28912706 100644 (file)
@@ -1179,7 +1179,7 @@ int main(int argc, char * argv[])
 
        lyx::lyxerr.setStream(cerr);
 
-       os::init(argc, argv);
+       os::init(argc, &argv);
 
        lyx::TeX2LyXApp app(argc, argv);
        return app.exec();