From 150bde522eabe8fdb6c644956e7d18c15af08349 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Tue, 9 Aug 2022 01:25:35 +0300 Subject: [PATCH 44/44] Rearrange FIELD_RANGE_ASSERT - Have the potentially fatal assert only after the verbose message has been logged - Do the "action" last, as it typically changes the state that the assert would use - In the no-failure case evaluate the "test" only once See osdn #45047 Signed-off-by: Marko Lindqvist --- common/networking/dataio_raw.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/common/networking/dataio_raw.c b/common/networking/dataio_raw.c index ac43f716c0..b10c89cdad 100644 --- a/common/networking/dataio_raw.c +++ b/common/networking/dataio_raw.c @@ -78,20 +78,21 @@ static DIO_GET_CONV_FUN get_conv_callback = get_conv; #endif #ifdef FIELD_RANGE_ASSERT -/* This evaluates _test_ twice. If that's a problem, - * it should evaluate it just once and store result to variable. - * That would lose verbosity of the assert message. */ +/* Do log_error() first, so we get its output even if + * fc_assert() is fatal. + * fc_assert() before the _action_ might fix + * what we should find out to fail. */ #define FIELD_RANGE_TEST(_test_, _action_, _format_, ...) \ - fc_assert(!(_test_)); \ if (_test_) { \ - _action_ \ log_error(_format_, ## __VA_ARGS__); \ + fc_assert(!(_test_)); \ + _action_ \ } #else /* FIELD_RANGE_ASSERT */ #define FIELD_RANGE_TEST(_test_, _action_, _format_, ...) \ if (_test_) { \ - _action_ \ log_error(_format_, ## __VA_ARGS__); \ + _action_ \ } #endif /* FIELD_RANGE_ASSERT */ -- 2.35.1