X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fsupport%2Ffiletools.cpp;h=60bd72f9054b5e6d9e3498ee2f8efcaa28159943;hb=76e99e9a20cf635d20effa597551f3a9af484465;hp=7bff99dcd149787d920d058377488a46a7dd4bee;hpb=84658d37e2eb1358c054ad41f3032f2b3684497f;p=lyx.git diff --git a/src/support/filetools.cpp b/src/support/filetools.cpp index 7bff99dcd1..60bd72f905 100644 --- a/src/support/filetools.cpp +++ b/src/support/filetools.cpp @@ -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; } @@ -1124,7 +1132,8 @@ cmd_ret const runCommand(string const & cmd) } -FileName const findtexfile(string const & fil, string const & /*format*/) +FileName const findtexfile(string const & fil, string const & /*format*/, + bool const onlykpse) { /* There is no problem to extend this function too use other methods to look for files. It could be setup to look @@ -1137,9 +1146,11 @@ FileName const findtexfile(string const & fil, string const & /*format*/) // If the file can be found directly, we just return a // absolute path version of it. - FileName const absfile(makeAbsPath(fil)); - if (absfile.exists()) - return absfile; + if (!onlykpse) { + FileName const absfile(makeAbsPath(fil)); + if (absfile.exists()) + return absfile; + } // Now we try to find it using kpsewhich. // It seems from the kpsewhich manual page that it is safe to use