Skip to content

Commit

Permalink
[core] Fixed SRT_ASSERT definition for non-MSVC compilers (#2423).
Browse files Browse the repository at this point in the history
* Define _DEBUG macro in Debug builds to enable SRT_ASSERT.
* Do not set _DEBUG/NDEBUG flags for MSVC.
* Use std::numeric_limits instead of INT_MAX.
  • Loading branch information
ethouris committed Aug 2, 2022
1 parent ee398a3 commit e48f43d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
31 changes: 22 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,28 @@ if (NOT DEFINED ENABLE_DEBUG)
endif()
endif()

# Set CMAKE_BUILD_TYPE properly, now that you know
# that ENABLE_DEBUG is set as it should.

if (ENABLE_DEBUG EQUAL 2)
set (CMAKE_BUILD_TYPE "RelWithDebInfo")
elseif (ENABLE_DEBUG) # 1, ON, YES, TRUE, Y, or any other non-zero number
set (CMAKE_BUILD_TYPE "Debug")
else()
set (CMAKE_BUILD_TYPE "Release")
# XXX This is a kind of workaround - this part to set the build
# type and associated other flags should not be done for build
# systems (cmake generators) that generate a multi-configuration
# build definition. At least it is known that MSVC does it and it
# sets _DEBUG and NDEBUG flags itself, so this shouldn't be done
# at all in this case.
if (NOT MICROSOFT)

# Set CMAKE_BUILD_TYPE properly, now that you know
# that ENABLE_DEBUG is set as it should.
if (ENABLE_DEBUG EQUAL 2)
set (CMAKE_BUILD_TYPE "RelWithDebInfo")
add_definitions(-DNDEBUG)
elseif (ENABLE_DEBUG) # 1, ON, YES, TRUE, Y, or any other non-zero number
set (CMAKE_BUILD_TYPE "Debug")

# Add _DEBUG macro in debug mode only, to enable SRT_ASSERT().
add_definitions(-D_DEBUG)
else()
set (CMAKE_BUILD_TYPE "Release")
add_definitions(-DNDEBUG)
endif()
endif()

message(STATUS "BUILD TYPE: ${CMAKE_BUILD_TYPE}")
Expand Down
5 changes: 3 additions & 2 deletions srtcore/buffer_rcv.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#if ENABLE_NEW_RCVBUFFER
#include <cmath>
#include <limits>
#include "buffer_rcv.h"
#include "logging.h"

Expand Down Expand Up @@ -87,7 +88,7 @@ CRcvBufferNew::CRcvBufferNew(int initSeqNo, size_t size, CUnitQueue* unitqueue,
, m_iPktsCount(0)
, m_uAvgPayloadSz(SRT_LIVE_DEF_PLSIZE)
{
SRT_ASSERT(size < INT_MAX); // All position pointers are integers
SRT_ASSERT(size < size_t(std::numeric_limits<int>::max())); // All position pointers are integers
}

CRcvBufferNew::~CRcvBufferNew()
Expand Down Expand Up @@ -135,7 +136,7 @@ int CRcvBufferNew::insert(CUnit* unit)
m_iMaxPosInc = offset + 1;

// Packet already exists
SRT_ASSERT(pos >= 0 && pos < m_szSize);
SRT_ASSERT(pos >= 0 && pos < int(m_szSize));
if (m_entries[pos].status != EntryState_Empty)
{
IF_RCVBUF_DEBUG(scoped_log.ss << " returns -1");
Expand Down

0 comments on commit e48f43d

Please sign in to comment.