Skip to content

Commit

Permalink
Remove invalid use of null references (undefined behaviour)
Browse files Browse the repository at this point in the history
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 f2911ac)
  • Loading branch information
qris committed Jan 15, 2018
1 parent ad86838 commit 61995c3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
1 change: 1 addition & 0 deletions infrastructure/m4/boxbackup_tests.m4
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ BOX_CHECK_CXX_FLAG(-Werror=return-type)
BOX_CHECK_CXX_FLAG(-Werror=non-virtual-dtor)
BOX_CHECK_CXX_FLAG(-Werror=delete-non-virtual-dtor)
BOX_CHECK_CXX_FLAG(-Werror=parentheses)
BOX_CHECK_CXX_FLAG(-Werror=undefined-bool-conversion)
BOX_CHECK_CXX_FLAG(-Werror=overloaded-virtual)
# This error is detected by MSVC, but not usually by GCC/Clang:
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58114
Expand Down
3 changes: 0 additions & 3 deletions lib/common/Timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 "
Expand Down
9 changes: 5 additions & 4 deletions test/common/testcommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,11 @@ void test_timers()
// 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);
Expand Down

0 comments on commit 61995c3

Please sign in to comment.