]> git.lyx.org Git - features.git/commitdiff
Catch exception in replaceEnvironmentPath
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 4 Jun 2018 08:51:11 +0000 (10:51 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 4 Jun 2018 09:39:41 +0000 (11:39 +0200)
This exception in the regex constructor is only theoretical (our regex
are hardcoded), but this is creating coverity noise.

Additionally, revert the following commits that are not needed anymore:
6b6fa94c: Catch exceptions to please coverity
c2ed75fd: Fixup 6b6fa94c: coverity says there are more possible exceptions.

This commit is better viewed with 'git show -b'.

src/LyX.cpp
src/Server.cpp
src/support/filetools.cpp

index 0e1b19faf664f849a37f6add26f620fbad54e2d8..4e97f7ae64b92286ef5aa0a3152349942c1f2e32 100644 (file)
@@ -471,45 +471,39 @@ void LyX::earlyExit(int status)
 
 int LyX::init(int & argc, char * argv[])
 {
-       try {
-               // check for any spurious extra arguments
-               // other than documents
-               for (int argi = 1; argi < argc ; ++argi) {
-                       if (argv[argi][0] == '-') {
-                               lyxerr << to_utf8(
-                                       bformat(_("Wrong command line option `%1$s'. Exiting."),
-                                                       from_utf8(os::utf8_argv(argi)))) << endl;
-                               return EXIT_FAILURE;
-                       }
-               }
-
-               // Initialization of LyX (reads lyxrc and more)
-               LYXERR(Debug::INIT, "Initializing LyX::init...");
-               bool success = init();
-               LYXERR(Debug::INIT, "Initializing LyX::init...done");
-               if (!success)
-                       return EXIT_FAILURE;
-               // Remaining arguments are assumed to be files to load.
-               for (int argi = 1; argi < argc; ++argi)
-                       pimpl_->files_to_load_.push_back(os::utf8_argv(argi));
-
-               if (!use_gui && pimpl_->files_to_load_.empty()) {
-                       lyxerr << to_utf8(_("Missing filename for this operation.")) << endl;
+       // check for any spurious extra arguments
+       // other than documents
+       for (int argi = 1; argi < argc ; ++argi) {
+               if (argv[argi][0] == '-') {
+                       lyxerr << to_utf8(
+                               bformat(_("Wrong command line option `%1$s'. Exiting."),
+                               from_utf8(os::utf8_argv(argi)))) << endl;
                        return EXIT_FAILURE;
                }
+       }
 
-               if (first_start) {
-                       pimpl_->files_to_load_.push_back(
-                               i18nLibFileSearch("examples", "splash.lyx").absFileName());
-               }
+       // Initialization of LyX (reads lyxrc and more)
+       LYXERR(Debug::INIT, "Initializing LyX::init...");
+       bool success = init();
+       LYXERR(Debug::INIT, "Initializing LyX::init...done");
+       if (!success)
+               return EXIT_FAILURE;
 
-               return EXIT_SUCCESS;
+       // Remaining arguments are assumed to be files to load.
+       for (int argi = 1; argi < argc; ++argi)
+               pimpl_->files_to_load_.push_back(os::utf8_argv(argi));
 
-       } catch (exception const &e) {
-               // This can happen _in_theory_ in replaceEnvironmentPath
-               lyxerr << "Caught exception `" << e.what() << "'." << endl;
+       if (!use_gui && pimpl_->files_to_load_.empty()) {
+               lyxerr << to_utf8(_("Missing filename for this operation.")) << endl;
                return EXIT_FAILURE;
        }
+
+       if (first_start) {
+               pimpl_->files_to_load_.push_back(
+                       i18nLibFileSearch("examples", "splash.lyx").absFileName());
+       }
+
+       return EXIT_SUCCESS;
 }
 
 
index 5f5d873f54d79e95d3534b4329bd931bf3fddd1f..a83911dc6910cd7eec2172006335dfb4cbd4cd38 100644 (file)
@@ -1067,10 +1067,7 @@ Server::~Server()
        string message;
        for (int i = 0; i != numclients_; ++i) {
                message = "LYXSRV:" + clients_[i] + ":bye\n";
-               // ignore exceptions, we are quitting anyway
-               try {
-                       pipes_.send(message);
-               } catch (...) {}
+               pipes_.send(message);
        }
 }
 
index 694ae53099a10755119fb34c569eea767820bc58..60bd72f9054b5e6d9e3498ee2f8efcaa28159943 100644 (file)
@@ -686,19 +686,27 @@ string const replaceEnvironmentPath(string const & path)
        // $[A-Za-z_][A-Za-z_0-9]*
        static string const envvar = "[$]([A-Za-z_][A-Za-z_0-9]*)";
 
-       static regex const envvar_br_re("(.*)" + envvar_br + "(.*)");
-       static regex const envvar_re("(.*)" + envvar + "(.*)");
-       string result = path;
-       while (1) {
-               smatch what;
-               if (!regex_match(result, what, envvar_br_re)) {
-                       if (!regex_match(result, what, envvar_re))
-                               break;
+       // Coverity thinks that the regex constructor can return an
+       // exception. We know that it is not true since our regex are
+       // hardcoded, but we have to protect against that nevertheless.
+       try {
+               static regex const envvar_br_re("(.*)" + envvar_br + "(.*)");
+               static regex const envvar_re("(.*)" + envvar + "(.*)");
+               string result = path;
+               while (1) {
+                       smatch what;
+                       if (!regex_match(result, what, envvar_br_re)) {
+                               if (!regex_match(result, what, envvar_re))
+                                       break;
+                       }
+                       string env_var = getEnv(what.str(2));
+                       result = what.str(1) + env_var + what.str(3);
                }
-               string env_var = getEnv(what.str(2));
-               result = what.str(1) + env_var + what.str(3);
+               return result;
+       } catch (exception const & e) {
+               LYXERR0("Something is very wrong: " << e.what());
+               return path;
        }
-       return result;
 }