Catch improbable exception

We know that the exception is correct, but coverity does not.
It would be much better to check that at compile time...
This commit is contained in:
Jean-Marc Lasgouttes 2019-07-13 00:24:21 +02:00
parent ca217fbfaa
commit 5e33e4fc2c

View File

@ -49,7 +49,6 @@ int timeout_min()
static string const python23_call(string const & binary, bool verbose = false) static string const python23_call(string const & binary, bool verbose = false)
{ {
const string version_info = " -c 'from __future__ import print_function;import sys; print(sys.version_info[:2], end=\"\")'"; const string version_info = " -c 'from __future__ import print_function;import sys; print(sys.version_info[:2], end=\"\")'";
static regex const python_reg("\\((\\d*), (\\d*)\\)");
// Default to "python" if no binary is given. // Default to "python" if no binary is given.
if (binary.empty()) if (binary.empty())
return "python -tt"; return "python -tt";
@ -60,8 +59,14 @@ static string const python23_call(string const & binary, bool verbose = false)
cmd_ret const out = runCommand(binary + version_info); cmd_ret const out = runCommand(binary + version_info);
smatch sm; smatch sm;
try {
static regex const python_reg("\\((\\d*), (\\d*)\\)");
if (out.first < 0 || !regex_match(out.second, sm, python_reg)) if (out.first < 0 || !regex_match(out.second, sm, python_reg))
return string(); return string();
} catch(regex_error const & /*e*/) {
LYXERR0("Regex error! This should not happen.");
return string();
}
int major = convert<int>(sm.str(1)); int major = convert<int>(sm.str(1));
int minor = convert<int>(sm.str(2)); int minor = convert<int>(sm.str(2));