Fix coverity issues about exceptions

There a some exceptions related to the fact that BOOST_ASSERT throws
an unhandled exception, which is fait enough. This is handled by
uploading a modeling file to coverity.

The second batch of issues are related to the use of lexical_cast in
convert.cpp. We use now a wrapper around boost::lexical_cast that does
not throw but return empty strings instead. I am not sure actually of
when lexical_cast could fail.
This commit is contained in:
Jean-Marc Lasgouttes 2017-03-24 16:44:14 +01:00
parent d7dfa27574
commit 2a0e4c199c
3 changed files with 31 additions and 2 deletions

View File

@ -9,6 +9,7 @@ SUBDIRS = cygwin
endif
EXTRA_DIST = coding/Rules coding/Recommendations \
coverity_modeling.cpp \
FORMAT lyx.rpm.README \
lyxserver lyx.spec.in lyx.spec \
LyX-Mac-binary-release.sh \

View File

@ -0,0 +1,13 @@
// This file is a modeling file for coverity
namespace lyx {
// Tell coverity that this function always exits
void doAssertWithCallstack(bool value)
{
if (!value) {
__coverity_panic__();
}
}
}

View File

@ -23,9 +23,24 @@
using namespace std;
namespace lyx {
namespace {
using boost::lexical_cast;
// A version of lexical cast that does not throw. Useful for when we convert to string
template<typename To, typename From>
To lexical_cast(From const & value, To const & defaultResult = To())
{
try {
return boost::lexical_cast<To>(value);
} catch(...) {
// Ignore all exceptions and use default.
return defaultResult;
}
}
}
namespace lyx {
template<>
string convert<string>(bool b)