From: Willy Tarreau Date: Wed, 27 Nov 2024 13:24:16 +0000 (+0100) Subject: BUG/MINOR: debug: COUNT_IF() should return true/false X-Git-Tag: v3.2-dev1~27 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7f64bb79fd;p=thirdparty%2Fhaproxy.git 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. --- diff --git a/include/haproxy/bug.h b/include/haproxy/bug.h index eb20773cb3..51317d2209 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