commit 2a0e4c199c4f18d80ec5a2ab452f3cf18eafc56c
Author: Jean-Marc Lasgouttes <[email protected]>
Date:   Fri Mar 24 16:44:14 2017 +0100

    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.
---
 development/Makefile.am           |    1 +
 development/coverity_modeling.cpp |   13 +++++++++++++
 src/support/convert.cpp           |   19 +++++++++++++++++--
 3 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/development/Makefile.am b/development/Makefile.am
index 95bde43..ff332aa 100644
--- a/development/Makefile.am
+++ b/development/Makefile.am
@@ -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 \
diff --git a/development/coverity_modeling.cpp 
b/development/coverity_modeling.cpp
new file mode 100644
index 0000000..baca854
--- /dev/null
+++ b/development/coverity_modeling.cpp
@@ -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__();
+       }
+}
+
+}
diff --git a/src/support/convert.cpp b/src/support/convert.cpp
index 076c9d7..f95aa4b 100644
--- a/src/support/convert.cpp
+++ b/src/support/convert.cpp
@@ -23,9 +23,24 @@
 
 using namespace std;
 
-namespace lyx {
+namespace {
+
+// 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;
+       }
+}
 
-using boost::lexical_cast;
+}
+
+
+namespace lyx {
 
 template<>
 string convert<string>(bool b)

Reply via email to