Catch exception in replaceEnvironmentPath

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'.
This commit is contained in:
Jean-Marc Lasgouttes 2018-06-04 10:51:11 +02:00
parent 08afacc239
commit 32f37250d5
3 changed files with 46 additions and 47 deletions

View File

@ -471,7 +471,6 @@ 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) {
@ -489,6 +488,7 @@ int LyX::init(int & argc, char * argv[])
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));
@ -504,12 +504,6 @@ int LyX::init(int & argc, char * argv[])
}
return EXIT_SUCCESS;
} catch (exception const &e) {
// This can happen _in_theory_ in replaceEnvironmentPath
lyxerr << "Caught exception `" << e.what() << "'." << endl;
return EXIT_FAILURE;
}
}

View 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 (...) {}
}
}

View File

@ -686,6 +686,10 @@ 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]*)";
// 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;
@ -699,6 +703,10 @@ string const replaceEnvironmentPath(string const & path)
result = what.str(1) + env_var + what.str(3);
}
return result;
} catch (exception const & e) {
LYXERR0("Something is very wrong: " << e.what());
return path;
}
}