mirror of
https://github.com/XRPLF/rippled.git
synced 2026-06-03 16:56:48 +00:00
refactor: Introduce XRPL_ASSERT_IF for amendment-gated assertions
Add XRPL_ASSERT_IF(guard, ...) to instrumentation.h — a conditional assertion that fires only when guard is true, using __VA_ARGS__ to match the XRPL_ASSERT_PARTS variadic convention and avoid bare-comma pitfalls in cond. guard is always evaluated (even in release builds where the assertion body is stripped), so it should be side-effect-free. Replace all amendment-gated XRPL_ASSERT / XRPL_ASSERT_PARTS call sites in LendingHelpers.cpp and MPTokenHelpers.cpp with the new macro. In doOverpayment, hoist rules.enabled(fixCleanup3_2_0) to a single bool to avoid three repeated set lookups, and inline the three intermediate Number values into a lambda so they are only computed when the guard fires.
This commit is contained in:
@@ -21,6 +21,13 @@
|
||||
#define XRPL_ASSERT ALWAYS_OR_UNREACHABLE
|
||||
#define XRPL_ASSERT_PARTS(cond, function, description, ...) \
|
||||
XRPL_ASSERT(cond, function " : " description)
|
||||
// clang-format off
|
||||
#define XRPL_ASSERT_IF(guard, ...) \
|
||||
do { \
|
||||
if ((guard)) \
|
||||
XRPL_ASSERT(__VA_ARGS__); \
|
||||
} while (false)
|
||||
// clang-format on
|
||||
|
||||
// How to use the instrumentation macros:
|
||||
//
|
||||
@@ -29,6 +36,11 @@
|
||||
// * XRPL_ASSERT_PARTS is for convenience, and works like XRPL_ASSERT, but
|
||||
// splits the message param into "function" and "description", then joins
|
||||
// them with " : " before passing to XRPL_ASSERT.
|
||||
// * XRPL_ASSERT_IF(guard, cond, message) fires the assertion only when guard
|
||||
// is true (e.g. an amendment is enabled). Equivalent to
|
||||
// `if (guard) XRPL_ASSERT(cond, message)` but safe to use in all statement
|
||||
// contexts. NOTE: guard is always evaluated — even in release builds where
|
||||
// the assertion itself is stripped — so keep it side-effect-free and cheap.
|
||||
// * ALWAYS if cond must be true _and_ the line must be reached during fuzzing.
|
||||
// Same like `assert` in normal use.
|
||||
// * REACHABLE if the line must be reached during fuzzing
|
||||
|
||||
Reference in New Issue
Block a user