From 7f64bb79fd35f22537ce5d05f59838e49db5cb10 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 27 Nov 2024 14:24:16 +0100 Subject: [PATCH] BUG/MINOR: debug: COUNT_IF() should return true/false The COUNT_IF() macro was initially meant to return true/false to be used in if() conditions but had an extra do { } while(0) that prevents it from doing so. Let's get rid of the do { } while(0) before the code generalizes to too many places. There's no impact on existing code, but may have to be backported if future fixes rely on it. --- include/haproxy/bug.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/haproxy/bug.h b/include/haproxy/bug.h index eb20773cb..51317d220 100644 --- a/include/haproxy/bug.h +++ b/include/haproxy/bug.h @@ -225,11 +225,11 @@ extern __attribute__((__weak__)) struct debug_count __stop_dbg_cnt HA_SECTION_S /* Core of the COUNT_IF() macro, checks the condition and counts one hit if * true. */ -#define _COUNT_IF(cond, file, line, ...) do { \ - (void)(unlikely(cond) ? ({ \ +#define _COUNT_IF(cond, file, line, ...) \ + (unlikely(cond) ? ({ \ __DBG_COUNT(cond, file, line, DBG_COUNT_IF, __VA_ARGS__); \ 1; /* let's return the true condition */ \ - }) : 0); } while (0) + }) : 0) /* DEBUG_GLITCHES enables counting the number of glitches per line of code. The * condition is empty (nothing to write there), except maybe __VA_ARGS at the @@ -245,7 +245,7 @@ extern __attribute__((__weak__)) struct debug_count __stop_dbg_cnt HA_SECTION_S #else /* USE_OBSOLETE_LINKER not defined below */ # define __DBG_COUNT(cond, file, line, type, ...) do { } while (0) -# define _COUNT_IF(cond, file, line, ...) do { } while (0) +# define _COUNT_IF(cond, file, line, ...) (cond) # define _COUNT_GLITCH(file, line, ...) do { } while (0) #endif