From fa457fbd3387661e1973a8f4e5cc2def79e0c625 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Mon, 8 Jun 2020 08:54:23 -0400 Subject: [PATCH 1/4] move-only: Move NDEBUG compile time check to util/check --- src/net_processing.cpp | 11 ++++------- src/util/check.h | 4 ++++ src/validation.cpp | 5 +---- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index d48745aef25..06a6557b3b1 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -13,10 +13,9 @@ #include #include #include -#include #include -#include #include +#include #include #include #include @@ -26,16 +25,14 @@ #include #include #include -#include +#include // For NDEBUG compile time check #include +#include +#include #include #include -#if defined(NDEBUG) -# error "Bitcoin cannot be compiled without assertions." -#endif - /** Expiration time for orphan transactions in seconds */ static constexpr int64_t ORPHAN_TX_EXPIRE_TIME = 20 * 60; /** Minimum time between orphan transactions expire time checks in seconds */ diff --git a/src/util/check.h b/src/util/check.h index 5c0f32cf519..5cc078b36b8 100644 --- a/src/util/check.h +++ b/src/util/check.h @@ -42,4 +42,8 @@ class NonFatalCheckError : public std::runtime_error } \ } while (false) +#if defined(NDEBUG) +#error "Cannot compile without assertions!" +#endif + #endif // BITCOIN_UTIL_CHECK_H diff --git a/src/validation.cpp b/src/validation.cpp index cbe89443b82..9f02db80c85 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -39,6 +39,7 @@ #include #include #include +#include // For NDEBUG compile time check #include #include #include @@ -51,10 +52,6 @@ #include -#if defined(NDEBUG) -# error "Bitcoin cannot be compiled without assertions." -#endif - #define MICRO 0.000001 #define MILLI 0.001 From fa6ef701adba1cb48535cac25fd43c742a82e40d Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Mon, 8 Jun 2020 08:47:10 -0400 Subject: [PATCH 2/4] util: Add Assert identity function The utility is primarily useful to dereference pointer types, which are known to be not null at that time. For example, the ArgsManager is known to exist when the wallets are started. Instead of silently relying on that assumption, Assert can be used to abort the program and avoid UB should the assumption ever be violated. --- src/test/util/mining.cpp | 4 ++-- src/test/util/setup_common.h | 1 + src/util/check.h | 12 +++++++++++- test/lint/lint-assertions.sh | 2 +- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/test/util/mining.cpp b/src/test/util/mining.cpp index dac7f1a07b8..b0c74954db7 100644 --- a/src/test/util/mining.cpp +++ b/src/test/util/mining.cpp @@ -11,6 +11,7 @@ #include #include #include