From 2537cccad34b64086ad2ff47db07c3674b9be07a Mon Sep 17 00:00:00 2001
From: Arseny Kapoulkine <arseny.kapoulkine@gmail.com>
Date: Sun, 12 Apr 2015 02:17:20 -0700
Subject: [PATCH] tests: Fix some Coverity issues

---
 tests/test_document.cpp     |  4 +++-
 tests/test_dom_modify.cpp   |  4 ++--
 tests/test_dom_traverse.cpp | 12 +++++++++++-
 3 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/tests/test_document.cpp b/tests/test_document.cpp
index 2c52030d..d81458ab 100644
--- a/tests/test_document.cpp
+++ b/tests/test_document.cpp
@@ -32,9 +32,11 @@ static bool load_file_in_memory(const char* path, char*& data, size_t& size)
 	if (!file) return false;
 
 	fseek(file, 0, SEEK_END);
-	size = static_cast<size_t>(ftell(file));
+	long length = ftell(file);
 	fseek(file, 0, SEEK_SET);
 
+	CHECK(length >= 0);
+	size = static_cast<size_t>(length);
 	data = new char[size];
 
 	CHECK(fread(data, 1, size, file) == size);
diff --git a/tests/test_dom_modify.cpp b/tests/test_dom_modify.cpp
index ae18171b..fc6dd590 100644
--- a/tests/test_dom_modify.cpp
+++ b/tests/test_dom_modify.cpp
@@ -644,7 +644,7 @@ TEST_XML(dom_node_remove_child, "<node><n1/><n2/><n3/><child><n4/></child></node
 
 TEST_XML(dom_node_remove_child_complex, "<node id='1'><n1 id1='1' id2='2'/><n2/><n3/><child><n4/></child></node>")
 {
-	doc.child(STR("node")).remove_child(STR("n1"));
+	CHECK(doc.child(STR("node")).remove_child(STR("n1")));
 
 	CHECK_NODE(doc, STR("<node id=\"1\"><n2 /><n3 /><child><n4 /></child></node>"));
 
@@ -1040,7 +1040,7 @@ TEST_XML(dom_node_append_buffer_remove, "<node>test</node>")
 
 	CHECK_NODE(doc, STR("<node>test</node>"));
 
-	doc.remove_child(STR("node"));
+	CHECK(doc.remove_child(STR("node")));
 
 	CHECK(!doc.first_child());
 }
diff --git a/tests/test_dom_traverse.cpp b/tests/test_dom_traverse.cpp
index 721a0794..4423dbe9 100644
--- a/tests/test_dom_traverse.cpp
+++ b/tests/test_dom_traverse.cpp
@@ -1085,14 +1085,24 @@ TEST_XML(dom_unspecified_bool_coverage, "<node attr='value'>text</node>")
 {
 	xml_node node = doc.first_child();
 
+	CHECK(node);
 	static_cast<void (*)(xml_node***)>(node)(0);
+
+	CHECK(node.first_attribute());
 	static_cast<void (*)(xml_attribute***)>(node.first_attribute())(0);
+
+	CHECK(node.text());
 	static_cast<void (*)(xml_text***)>(node.text())(0);
 
 #ifndef PUGIXML_NO_XPATH
 	xpath_query q(STR("/node"));
 
+	CHECK(q);
 	static_cast<void (*)(xpath_query***)>(q)(0);
-	static_cast<void (*)(xpath_node***)>(q.evaluate_node(doc))(0);
+
+	xpath_node qn = q.evaluate_node(doc);
+
+	CHECK(qn);
+	static_cast<void (*)(xpath_node***)>(qn)(0);
 #endif
 }
-- 
GitLab