Skip to content

Commit

Permalink
cid#318830 help coverity see assert
Browse files Browse the repository at this point in the history
and

cid#318839 Explicit null dereferenced
cid#318838 Explicit null dereferenced

Signed-off-by: Caolán McNamara <[email protected]>
Change-Id: I34685ea04722aeccc21910283fa4819dbf45c012
  • Loading branch information
caolanm authored and vmiklos committed Oct 10, 2023
1 parent 679241b commit 4ec1a37
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 8 additions & 0 deletions test/TileQueueTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,17 @@ void TileQueueTests::testSenderQueue()

LOK_ASSERT_EQUAL_STR(true, queue.dequeue(item));
LOK_ASSERT_EQUAL(static_cast<size_t>(2), queue.size());
LOK_ASSERT(item);
LOK_ASSERT_EQUAL(messages[0], std::string(item->data().data(), item->data().size()));

LOK_ASSERT_EQUAL_STR(true, queue.dequeue(item));
LOK_ASSERT_EQUAL(static_cast<size_t>(1), queue.size());
LOK_ASSERT(item);
LOK_ASSERT_EQUAL(messages[1], std::string(item->data().data(), item->data().size()));

LOK_ASSERT_EQUAL_STR(true, queue.dequeue(item));
LOK_ASSERT_EQUAL(static_cast<size_t>(0), queue.size());
LOK_ASSERT(item);
LOK_ASSERT_EQUAL(messages[2], std::string(item->data().data(), item->data().size()));

LOK_ASSERT_EQUAL(static_cast<size_t>(0), queue.size());
Expand Down Expand Up @@ -345,6 +348,8 @@ void TileQueueTests::testSenderQueueTileDeduplication()
LOK_ASSERT_EQUAL(static_cast<size_t>(1), queue.size());
LOK_ASSERT_EQUAL_STR(true, queue.dequeue(item));

LOK_ASSERT(item);

// The last one should persist.
LOK_ASSERT_EQUAL(dup_messages[2], std::string(item->data().data(), item->data().size()));

Expand Down Expand Up @@ -379,14 +384,17 @@ void TileQueueTests::testInvalidateViewCursorDeduplication()

LOK_ASSERT_EQUAL_STR(true, queue.dequeue(item));
LOK_ASSERT_EQUAL(static_cast<size_t>(2), queue.size());
LOK_ASSERT(item);
LOK_ASSERT_EQUAL(view_messages[0], std::string(item->data().data(), item->data().size()));

LOK_ASSERT_EQUAL_STR(true, queue.dequeue(item));
LOK_ASSERT_EQUAL(static_cast<size_t>(1), queue.size());
LOK_ASSERT(item);
LOK_ASSERT_EQUAL(view_messages[1], std::string(item->data().data(), item->data().size()));

LOK_ASSERT_EQUAL_STR(true, queue.dequeue(item));
LOK_ASSERT_EQUAL(static_cast<size_t>(0), queue.size());
LOK_ASSERT(item);
LOK_ASSERT_EQUAL(view_messages[2], std::string(item->data().data(), item->data().size()));

LOK_ASSERT_EQUAL(static_cast<size_t>(0), queue.size());
Expand Down
7 changes: 3 additions & 4 deletions test/lokassert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ std::string inline lokFormatAssertEq(const char* expected_name, const std::strin
return oss.str();
}

#ifdef LOK_ABORT_ON_ASSERTION
#if defined(LOK_ABORT_ON_ASSERTION) || defined(__COVERITY__)
#define LOK_ASSERT_IMPL(X) assert(X);
#else
#define LOK_ASSERT_IMPL(X)
Expand Down Expand Up @@ -115,16 +115,15 @@ inline constexpr bool failed() { return false; }
using namespace test::detail; \
if (!failed()) \
{ \
auto&& cond##__LINE__ = !!(condition); \
if (!cond##__LINE__) \
if (!(condition)) \
{ \
std::ostringstream oss##__LINE__; \
oss##__LINE__ << message; \
const auto msg##__LINE__ = oss##__LINE__.str(); \
TST_LOG("ERROR: Assertion failure: " \
<< (msg##__LINE__.empty() ? "" : msg##__LINE__ + ". ") \
<< "Condition: " << (#condition)); \
LOK_ASSERT_IMPL(cond##__LINE__); \
LOK_ASSERT_IMPL(!#condition); /* NOLINT(misc-static-assert) */ \
CPPUNIT_ASSERT_MESSAGE((msg##__LINE__), condition); \
} \
else if (!silent) \
Expand Down

0 comments on commit 4ec1a37

Please sign in to comment.