From 964f8f40639453ddb42aa3d2aea9e1519b2d74cb Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Fri, 26 Aug 2022 06:53:49 +0200 Subject: fix macros do { ... } while (0) is objectively better: https://stackoverflow.com/q/1067226/514684 --- src/git.c | 4 ++-- src/log.h | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/git.c b/src/git.c index 3572d67..adf40e4 100644 --- a/src/git.c +++ b/src/git.c @@ -5,11 +5,11 @@ #include #define git_print_error(fn) \ - { \ + do { \ const git_error *error = git_error_last(); \ const char *msg = error && error->message ? error->message : "???"; \ print_error("%s: %s\n", fn, msg); \ - } + } while (0) int libgit_init() { diff --git a/src/log.h b/src/log.h index ea9aacb..33e3040 100644 --- a/src/log.h +++ b/src/log.h @@ -10,30 +10,30 @@ #define CONCAT(a, b) CONCAT_INNER(a, b) #define print_errno(s) \ - { \ + do { \ fprintf(stderr, "%s(%d): ", basename(__FILE__), __LINE__); \ perror(s); \ - } + } while (0) #define pthread_print_errno(var, s) \ - { \ + do { \ errno = var; \ print_errno(s); \ var = -var; \ - } + } while (0) #define pthread_check(expr, s) \ - { \ + do { \ int CONCAT(ret, __LINE__) = expr; \ if (CONCAT(ret, __LINE__)) \ pthread_print_errno(CONCAT(ret, __LINE__), s); \ - } + } while (0) #define print_error(...) \ - { \ + do { \ fprintf(stderr, "%s(%d): ", basename(__FILE__), __LINE__); \ fprintf(stderr, __VA_ARGS__); \ - } + } while (0) #define print_log(...) printf(__VA_ARGS__) -- cgit v1.2.3