From e48f43d546457f3386702d032d7d7e08cd0a5b19 Mon Sep 17 00:00:00 2001 From: Sektor van Skijlen Date: Tue, 2 Aug 2022 12:44:49 +0200 Subject: [PATCH] [core] Fixed SRT_ASSERT definition for non-MSVC compilers (#2423). * 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. --- CMakeLists.txt | 31 ++++++++++++++++++++++--------- srtcore/buffer_rcv.cpp | 5 +++-- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ac7a0b139..8e211f2e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}") diff --git a/srtcore/buffer_rcv.cpp b/srtcore/buffer_rcv.cpp index bea9212d6..2ee763a00 100644 --- a/srtcore/buffer_rcv.cpp +++ b/srtcore/buffer_rcv.cpp @@ -1,5 +1,6 @@ #if ENABLE_NEW_RCVBUFFER #include +#include #include "buffer_rcv.h" #include "logging.h" @@ -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::max())); // All position pointers are integers } CRcvBufferNew::~CRcvBufferNew() @@ -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");