Dear all,

I have an issue with a coverity issue (err...). In the attached screenshot, coverity tells me, as I see it that buffer() may throw an exception. But my reading of the code is that this can not happen because of isBufferLoaded().

Did I miss something? Otherwise I will need to annotate the code as in the (still incomplete) attached patch.

JMarc
>From 63608e43e543cee026b92dc72d63f9ea306576cf Mon Sep 17 00:00:00 2001
From: Jean-Marc Lasgouttes <lasgout...@lyx.org>
Date: Mon, 27 Mar 2017 16:18:14 +0200
Subject: [PATCH] Annotate destructors to please coverity

Coverity flags this code as not handling exception that may happen in buffer().

My own analysis is that this can never happen because isBufferValid()
does check whether buffer_ is null.

Any insght appreciated. The commit should be expeanded to more cases, actually.
---
 src/insets/Inset.h          | 4 ++--
 src/insets/InsetBibitem.cpp | 3 +++
 src/insets/InsetBibtex.cpp  | 4 ++++
 src/insets/InsetInclude.cpp | 3 +++
 4 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/insets/Inset.h b/src/insets/Inset.h
index 5d7f27f..3d93904 100644
--- a/src/insets/Inset.h
+++ b/src/insets/Inset.h
@@ -112,8 +112,8 @@ public:
 	/// reset associated Buffer to null value
 	virtual void resetBuffer();
 	/// retrieve associated Buffer
-	virtual Buffer & buffer();
-	virtual Buffer const & buffer() const;
+	Buffer & buffer();
+	Buffer const & buffer() const;
 	/// Returns true if buffer_ actually points to a Buffer that has
 	/// been loaded into LyX and is still open. Note that this will
 	/// always return false for cloned Buffers. If you want to allow
diff --git a/src/insets/InsetBibitem.cpp b/src/insets/InsetBibitem.cpp
index 18a261a..1c8bc78 100644
--- a/src/insets/InsetBibitem.cpp
+++ b/src/insets/InsetBibitem.cpp
@@ -68,6 +68,9 @@ InsetBibitem::InsetBibitem(Buffer * buf, InsetCommandParams const & p)
 InsetBibitem::~InsetBibitem()
 {
 	if (isBufferLoaded())
+		/* Coverity believs that this may throw an exception, but
+		 * actually this code path is not taken when buffer_ == 0 */
+		// coverity[exn_spec_violation]
 		buffer().invalidateBibinfoCache();
 }
 
diff --git a/src/insets/InsetBibtex.cpp b/src/insets/InsetBibtex.cpp
index ef79481..63ae865 100644
--- a/src/insets/InsetBibtex.cpp
+++ b/src/insets/InsetBibtex.cpp
@@ -68,7 +68,11 @@ InsetBibtex::InsetBibtex(Buffer * buf, InsetCommandParams const & p)
 InsetBibtex::~InsetBibtex()
 {
 	if (isBufferLoaded()) {
+		/* Coverity believs that this may throw an exception, but
+		 * actually this code path is not taken when buffer_ == 0 */
+		// coverity[exn_spec_violation]
 		buffer().invalidateBibfileCache();
+		// coverity[exn_spec_violation]
 		buffer().removeBiblioTempFiles();
 	}
 }
diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp
index 9b5c3f0..21f4a3f 100644
--- a/src/insets/InsetInclude.cpp
+++ b/src/insets/InsetInclude.cpp
@@ -198,6 +198,9 @@ InsetInclude::InsetInclude(InsetInclude const & other)
 InsetInclude::~InsetInclude()
 {
 	if (isBufferLoaded())
+		/* Coverity believs that this may throw an exception, but
+		 * actually this code path is not taken when buffer_ == 0 */
+		// coverity[exn_spec_violation]
 		buffer().invalidateBibfileCache();
 	delete label_;
 }
-- 
2.9.3

Reply via email to