From 99209d0339b3a80ed8503c0aaa8e4f3abb99c6f2 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Wed, 6 Apr 2022 15:38:45 +0200 Subject: [PATCH] Enable stream sanity checks in debug builds Enable this automatically for developers so we increase the chance of these problems getting caught. There is a risk of overhead though so keep them disabled for release builds. --- CMakeLists.txt | 5 +++++ common/rdr/InStream.h | 4 +++- win/CMakeLists.txt | 4 ---- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 57de9baa..1c6b99fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,6 +62,11 @@ set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -UNDEBUG") set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -UNDEBUG") set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -UNDEBUG") +# But extra debug checks are still gated by this custom define +IF(CMAKE_BUILD_TYPE MATCHES Debug) + add_definitions(-D_DEBUG) +ENDIF() + # Make sure we get a sane C version set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99") diff --git a/common/rdr/InStream.h b/common/rdr/InStream.h index 60ea4997..c02e967f 100644 --- a/common/rdr/InStream.h +++ b/common/rdr/InStream.h @@ -31,7 +31,9 @@ // Check that callers are using InStream properly, // useful when writing new protocol handling -#undef RFB_INSTREAM_CHECK +#ifdef _DEBUG +#define RFB_INSTREAM_CHECK +#endif namespace rdr { diff --git a/win/CMakeLists.txt b/win/CMakeLists.txt index cd6fc34f..951f16ad 100644 --- a/win/CMakeLists.txt +++ b/win/CMakeLists.txt @@ -2,10 +2,6 @@ include_directories(${CMAKE_SOURCE_DIR}/common ${CMAKE_SOURCE_DIR}/win) configure_file(resdefs.h.in ${CMAKE_CURRENT_BINARY_DIR}/resdefs.h) -IF(CMAKE_BUILD_TYPE MATCHES Debug) - add_definitions(-D_DEBUG) -ENDIF() - add_subdirectory(rfb_win32) if(BUILD_WINVNC) -- 2.39.5