summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2017-11-20 21:56:37 +0000
committerChris Wilson <chris+github@qwirx.com>2017-11-26 20:46:47 +0000
commit447c2cd3d6884b8383884dbbfe65db845ea5c04d (patch)
treed3358b504b37433871a83afcbb520141d327527b
parentb7c6a133b8868223bc39084968e0cac332fd4dfe (diff)
Remove invalid use of null references (undefined behaviour)
Enable the relevant compiler warning as an error, if supported (-Werror=undefined-bool-conversion). http://www.gotw.ca/conv/002.htm http://stackoverflow.com/questions/2165078/a-reference-can-not-be-null-or-it-can-be-null (cherry picked from commit f2911acac0c8375a08ecc0a55f853a5a59c4d511) (cherry picked from commit 5a50b98401302a5ba89366e4c0f8cccdd88d8722)
-rw-r--r--lib/common/Timer.cpp3
-rw-r--r--test/common/testcommon.cpp9
2 files changed, 5 insertions, 7 deletions
diff --git a/lib/common/Timer.cpp b/lib/common/Timer.cpp
index 6ce84b7d..78fbeadc 100644
--- a/lib/common/Timer.cpp
+++ b/lib/common/Timer.cpp
@@ -151,7 +151,6 @@ void Timers::AssertInitialised()
void Timers::Add(Timer& rTimer)
{
ASSERT(spTimers);
- ASSERT(&rTimer);
BOX_TRACE(TIMER_ID_OF(rTimer) " added to global queue, rescheduling");
spTimers->push_back(&rTimer);
Reschedule();
@@ -168,8 +167,6 @@ void Timers::Add(Timer& rTimer)
// --------------------------------------------------------------------------
void Timers::Remove(Timer& rTimer)
{
- ASSERT(&rTimer);
-
if(!spTimers)
{
BOX_WARNING(TIMER_ID_OF(rTimer) " was still active after "
diff --git a/test/common/testcommon.cpp b/test/common/testcommon.cpp
index bd75ac37..3de7da1d 100644
--- a/test/common/testcommon.cpp
+++ b/test/common/testcommon.cpp
@@ -312,10 +312,11 @@ int test(int argc, const char *argv[])
// Check that using timer methods without initialisation
// throws an assertion failure. Can only do this in debug mode
#ifndef BOX_RELEASE_BUILD
- TEST_CHECK_THROWS(Timers::Add(*(Timer*)NULL),
- CommonException, AssertFailed);
- TEST_CHECK_THROWS(Timers::Remove(*(Timer*)NULL),
- CommonException, AssertFailed);
+ {
+ Timer tim(0, "tim");
+ TEST_CHECK_THROWS(Timers::Add(tim), CommonException, AssertFailed);
+ Timers::Remove(tim);
+ }
#endif
// TEST_CHECK_THROWS(Timers::Signal(), CommonException, AssertFailed);