From 4ecc3f3c09677c6d932c43ad801c2a03d70f7f65 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Thu, 28 Feb 2019 18:00:31 +0000 Subject: [PATCH] Fix a couple of syntactically dangerous macros. The live versions of the dmemdump macros had a trailing semicolon in the expansion, which would cause them to break if used in the wrong syntactic context (e.g. between if and else with the natural semicolon at the call site). The conditioned-out versions of those and of debug() itself expanded to the empty string in place of the more usual ((void)0). And SECOND_PASS_ONLY in gtkmain.c's command-line handling should have had the standard do ... while(0) wrapper to make it reliably a single statement. --- misc.h | 10 +++++----- unix/gtkmain.c | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/misc.h b/misc.h index 3b1c6de6..8da4fdba 100644 --- a/misc.h +++ b/misc.h @@ -222,12 +222,12 @@ static inline NORETURN void unreachable_internal(void) { abort(); } void debug_printf(const char *fmt, ...); void debug_memdump(const void *buf, int len, bool L); #define debug(...) (debug_printf(__VA_ARGS__)) -#define dmemdump(buf,len) debug_memdump (buf, len, false); -#define dmemdumpl(buf,len) debug_memdump (buf, len, true); +#define dmemdump(buf,len) (debug_memdump(buf, len, false)) +#define dmemdumpl(buf,len) (debug_memdump(buf, len, true)) #else -#define debug(...) -#define dmemdump(buf,len) -#define dmemdumpl(buf,len) +#define debug(...) ((void)0) +#define dmemdump(buf,len) ((void)0) +#define dmemdumpl(buf,len) ((void)0) #endif #ifndef lenof diff --git a/unix/gtkmain.c b/unix/gtkmain.c index 6a3d25ed..20826726 100644 --- a/unix/gtkmain.c +++ b/unix/gtkmain.c @@ -330,7 +330,7 @@ bool do_cmdline(int argc, char **argv, bool do_everything, Conf *conf) } else \ val = *++argv; \ } -#define SECOND_PASS_ONLY { if (!do_everything) continue; } +#define SECOND_PASS_ONLY do { if (!do_everything) continue; } while (0) while (--argc > 0) { const char *p = *++argv;