From 139307865a32a1a229e7517946e979e19e2f42c0 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 20 Feb 2026 14:20:53 +0100 Subject: [PATCH] clang-tidy: check `bugprone-macro-parentheses`, fix fallouts Also: - lib/parsedate: avoid relying on side-effect of missing parentheses. - lib/http: drop redundant parentheses. - fix cases in headers missed by clang-tidy. Ref: https://clang.llvm.org/extra/clang-tidy/checks/bugprone/macro-parentheses.html Closes #20647 --- .clang-tidy.yml | 1 + include/curl/curl.h | 7 +- lib/cf-socket.c | 2 +- lib/cfilters.h | 2 +- lib/curl_sasl.h | 2 +- lib/curl_share.h | 4 +- lib/curlx/strparse.c | 2 +- lib/ftp.c | 4 +- lib/getinfo.c | 2 +- lib/hash.c | 2 +- lib/http.c | 4 +- lib/http2.c | 6 +- lib/http_aws_sigv4.c | 20 ++--- lib/idn.c | 2 +- lib/mprintf.c | 4 +- lib/parsedate.c | 142 ++++++++++++++++++------------------ lib/setopt.c | 4 +- lib/sigpipe.h | 8 +- lib/telnet.c | 22 +++--- lib/uint-hash.c | 2 +- lib/url.c | 2 +- lib/urlapi.c | 16 ++-- lib/urldata.h | 2 +- src/tool_cb_wrt.c | 4 +- src/tool_parsecfg.c | 2 +- src/tool_setopt.c | 2 +- src/tool_setopt.h | 2 +- src/tool_vms.h | 7 +- src/var.c | 2 +- tests/libtest/first.h | 8 +- tests/libtest/lib2405.c | 2 +- tests/libtest/lib557.c | 2 +- tests/libtest/mk-lib1521.pl | 10 ++- tests/libtest/unitcheck.h | 8 +- tests/server/first.h | 4 +- tests/server/tftpd.c | 4 +- 36 files changed, 163 insertions(+), 156 deletions(-) diff --git a/.clang-tidy.yml b/.clang-tidy.yml index b025d564d8..83068685a8 100644 --- a/.clang-tidy.yml +++ b/.clang-tidy.yml @@ -11,6 +11,7 @@ Checks: - -clang-analyzer-security.insecureAPI.bzero # for FD_ZERO() (seen on macOS) - -clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling - -clang-diagnostic-nullability-extension + - bugprone-macro-parentheses - bugprone-redundant-branch-condition - bugprone-suspicious-realloc-usage - misc-const-correctness diff --git a/include/curl/curl.h b/include/curl/curl.h index e2c1c5d39d..9ab580bb02 100644 --- a/include/curl/curl.h +++ b/include/curl/curl.h @@ -142,7 +142,7 @@ typedef SOCKET curl_socket_t; #define CURL_SOCKET_BAD INVALID_SOCKET #else typedef int curl_socket_t; -#define CURL_SOCKET_BAD -1 +#define CURL_SOCKET_BAD (-1) #endif #define curl_socket_typedef #endif /* curl_socket_typedef */ @@ -1117,8 +1117,9 @@ typedef CURLSTScode (*curl_hstswrite_callback)(CURL *easy, /* *STRINGPOINT is an alias for OBJECTPOINT to allow tools to extract the string options from the header file */ -#define CURLOPT(na,t,nu) na = t + nu -#define CURLOPTDEPRECATED(na,t,nu,v,m) na CURL_DEPRECATED(v,m) = t + nu +#define CURLOPT(na, t, nu) na = ((t) + (nu)) +#define CURLOPTDEPRECATED(na, t, nu, v, m) na CURL_DEPRECATED(v, m) \ + = ((t) + (nu)) /* CURLOPT aliases that make no runtime difference */ diff --git a/lib/cf-socket.c b/lib/cf-socket.c index aa8d8a7ca8..6cec4b4a49 100644 --- a/lib/cf-socket.c +++ b/lib/cf-socket.c @@ -105,7 +105,7 @@ static void tcpnodelay(struct Curl_cfilter *cf, (defined(_WIN32) && !defined(TCP_KEEPIDLE)) /* Solaris < 11.4, DragonFlyBSD < 500702 and Windows < 10.0.16299 * use millisecond units. */ -#define KEEPALIVE_FACTOR(x) (x *= 1000) +#define KEEPALIVE_FACTOR(x) ((x) *= 1000) #else #define KEEPALIVE_FACTOR(x) #endif diff --git a/lib/cfilters.h b/lib/cfilters.h index cb52f3265f..e3ce9577f9 100644 --- a/lib/cfilters.h +++ b/lib/cfilters.h @@ -348,7 +348,7 @@ unsigned char Curl_conn_cf_get_transport(struct Curl_cfilter *cf, const char *Curl_conn_cf_get_alpn_negotiated(struct Curl_cfilter *cf, struct Curl_easy *data); -#define CURL_CF_SSL_DEFAULT -1 +#define CURL_CF_SSL_DEFAULT (-1) #define CURL_CF_SSL_DISABLE 0 #define CURL_CF_SSL_ENABLE 1 diff --git a/lib/curl_sasl.h b/lib/curl_sasl.h index 8432d261ec..5e03bf3565 100644 --- a/lib/curl_sasl.h +++ b/lib/curl_sasl.h @@ -129,7 +129,7 @@ struct SASL { /* This is used to test whether the line starts with the given mechanism */ #define sasl_mech_equal(line, wordlen, mech) \ - (wordlen == (sizeof(mech) - 1) / sizeof(char) && \ + ((wordlen) == (sizeof(mech) - 1) / sizeof(char) && \ !memcmp(line, mech, wordlen)) /* Convert a mechanism name to a token */ diff --git a/lib/curl_share.h b/lib/curl_share.h index 3fcaaecd4a..b7746fe68c 100644 --- a/lib/curl_share.h +++ b/lib/curl_share.h @@ -70,8 +70,8 @@ CURLSHcode Curl_share_lock(struct Curl_easy *, curl_lock_data, CURLSHcode Curl_share_unlock(struct Curl_easy *, curl_lock_data); /* convenience macro to check if this handle is using a shared SSL spool */ -#define CURL_SHARE_ssl_scache(data) (data->share && \ - (data->share->specifier & \ +#define CURL_SHARE_ssl_scache(data) ((data)->share && \ + ((data)->share->specifier & \ (1 << CURL_LOCK_DATA_SSL_SESSION))) #endif /* HEADER_CURL_SHARE_H */ diff --git a/lib/curlx/strparse.c b/lib/curlx/strparse.c index f11b58b7ee..83ff8c904c 100644 --- a/lib/curlx/strparse.c +++ b/lib/curlx/strparse.c @@ -140,7 +140,7 @@ int curlx_str_singlespace(const char **linep) /* given an ASCII character and max ascii, return TRUE if valid */ #define valid_digit(x, m) \ - (((x) >= '0') && ((x) <= m) && curlx_hexasciitable[(x) - '0']) + (((x) >= '0') && ((x) <= (m)) && curlx_hexasciitable[(x) - '0']) /* We use 16 for the zero index (and the necessary bitwise AND in the loop) to be able to have a non-zero value there to make valid_digit() able to diff --git a/lib/ftp.c b/lib/ftp.c index cbfe825628..368bb40a62 100644 --- a/lib/ftp.c +++ b/lib/ftp.c @@ -78,10 +78,10 @@ /* macro to check for a three-digit ftp status code at the start of the given string */ #define STATUSCODE(line) \ - (ISDIGIT(line[0]) && ISDIGIT(line[1]) && ISDIGIT(line[2])) + (ISDIGIT((line)[0]) && ISDIGIT((line)[1]) && ISDIGIT((line)[2])) /* macro to check for the last line in an FTP server response */ -#define LASTLINE(line) (STATUSCODE(line) && (' ' == line[3])) +#define LASTLINE(line) (STATUSCODE(line) && (' ' == (line)[3])) #ifdef CURLVERBOSE /* for tracing purposes */ diff --git a/lib/getinfo.c b/lib/getinfo.c index fd0d483f0a..dedafd382e 100644 --- a/lib/getinfo.c +++ b/lib/getinfo.c @@ -379,7 +379,7 @@ static CURLcode getinfo_long(struct Curl_easy *data, CURLINFO info, return CURLE_OK; } -#define DOUBLE_SECS(x) (double)(x) / 1000000 +#define DOUBLE_SECS(x) ((double)(x) / 1000000) static CURLcode getinfo_offt(struct Curl_easy *data, CURLINFO info, curl_off_t *param_offt) diff --git a/lib/hash.c b/lib/hash.c index 74cfb2b3a8..8095ca2e45 100644 --- a/lib/hash.c +++ b/lib/hash.c @@ -155,7 +155,7 @@ static void hash_elem_link(struct Curl_hash *h, ++h->size; } -#define CURL_HASH_SLOT(x, y, z) x->table[x->hash_func(y, z, x->slots)] +#define CURL_HASH_SLOT(x, y, z) x->table[(x)->hash_func(y, z, (x)->slots)] #define CURL_HASH_SLOT_ADDR(x, y, z) &CURL_HASH_SLOT(x, y, z) void *Curl_hash_add2(struct Curl_hash *h, void *key, size_t key_len, void *p, diff --git a/lib/http.c b/lib/http.c index f0a1e57e9d..afad728b50 100644 --- a/lib/http.c +++ b/lib/http.c @@ -3182,11 +3182,11 @@ static statusline checkprotoprefix(struct Curl_easy *data, /* HTTP header has field name `n` (a string constant) */ #define HD_IS(hd, hdlen, n) \ - (((hdlen) >= (sizeof(n) - 1)) && curl_strnequal((n), (hd), (sizeof(n) - 1))) + (((hdlen) >= (sizeof(n) - 1)) && curl_strnequal(n, hd, sizeof(n) - 1)) #define HD_VAL(hd, hdlen, n) \ ((((hdlen) >= (sizeof(n) - 1)) && \ - curl_strnequal((n), (hd), (sizeof(n) - 1)))? (hd + (sizeof(n) - 1)) : NULL) + curl_strnequal(n, hd, sizeof(n) - 1)) ? ((hd) + (sizeof(n) - 1)) : NULL) /* HTTP header has field name `n` (a string constant) and contains `v` * (a string constant) in its value(s) */ diff --git a/lib/http2.c b/lib/http2.c index b01f6d5003..8712934a5c 100644 --- a/lib/http2.c +++ b/lib/http2.c @@ -260,9 +260,9 @@ static CURLcode cf_h2_update_settings(struct cf_h2_ctx *ctx, return CURLE_OK; } -#define H2_STREAM_CTX(ctx, data) \ - ((struct h2_stream_ctx *)( \ - data? Curl_uint32_hash_get(&(ctx)->streams, (data)->mid) : NULL)) +#define H2_STREAM_CTX(ctx, data) \ + ((struct h2_stream_ctx *)( \ + (data) ? Curl_uint32_hash_get(&(ctx)->streams, (data)->mid) : NULL)) static struct h2_stream_ctx *h2_stream_ctx_create(struct cf_h2_ctx *ctx) { diff --git a/lib/http_aws_sigv4.c b/lib/http_aws_sigv4.c index ea1a7ff758..bb00bb5b49 100644 --- a/lib/http_aws_sigv4.c +++ b/lib/http_aws_sigv4.c @@ -38,16 +38,16 @@ #include -#define HMAC_SHA256(k, kl, d, dl, o) \ - do { \ - result = Curl_hmacit(&Curl_HMAC_SHA256, \ - (const unsigned char *)k, \ - kl, \ - (const unsigned char *)d, \ - dl, o); \ - if(result) { \ - goto fail; \ - } \ +#define HMAC_SHA256(k, kl, d, dl, o) \ + do { \ + result = Curl_hmacit(&Curl_HMAC_SHA256, \ + (const unsigned char *)(k), \ + kl, \ + (const unsigned char *)(d), \ + dl, o); \ + if(result) { \ + goto fail; \ + } \ } while(0) #define TIMESTAMP_SIZE 17 diff --git a/lib/idn.c b/lib/idn.c index 00e2fc6e4c..2db4f6d79e 100644 --- a/lib/idn.c +++ b/lib/idn.c @@ -37,7 +37,7 @@ idn2_lookup_u8((const uint8_t *)name, (uint8_t **)host, flags) #else #define IDN2_LOOKUP(name, host, flags) \ - idn2_lookup_ul((const char *)name, (char **)host, flags) + idn2_lookup_ul((const char *)(name), (char **)(host), flags) #endif #endif /* USE_LIBIDN2 */ diff --git a/lib/mprintf.c b/lib/mprintf.c index 5a3349b457..6d267e18cd 100644 --- a/lib/mprintf.c +++ b/lib/mprintf.c @@ -40,7 +40,7 @@ const unsigned char Curl_udigits[] = "0123456789ABCDEF"; #define OUTCHAR(x) \ do { \ - if(stream((unsigned char)x, userp)) \ + if(stream((unsigned char)(x), userp)) \ return TRUE; \ (*donep)++; \ } while(0) @@ -145,7 +145,7 @@ static int dollarstring(const char *p, const char **end) } #define is_arg_used(x, y) ((x)[(y) / 8] & (1 << ((y) & 7))) -#define mark_arg_used(x, y) ((x)[y / 8] |= (unsigned char)(1 << ((y) & 7))) +#define mark_arg_used(x, y) ((x)[(y) / 8] |= (unsigned char)(1 << ((y) & 7))) /* * Parse the format string. diff --git a/lib/parsedate.c b/lib/parsedate.c index 744efc4ed3..3775cb6e1d 100644 --- a/lib/parsedate.c +++ b/lib/parsedate.c @@ -93,7 +93,7 @@ const char * const Curl_month[] = { #endif #define PARSEDATE_OK 0 -#define PARSEDATE_FAIL -1 +#define PARSEDATE_FAIL (-1) #ifndef CURL_DISABLE_PARSEDATE @@ -113,84 +113,84 @@ struct tzinfo { /* Here's a bunch of frequently used time zone names. These were supported by the old getdate parser. */ -#define tDAYZONE -60 /* offset for daylight savings time */ +#define tDAYZONE (-60) /* offset for daylight savings time */ static const struct tzinfo tz[] = { - { "GMT", 0 }, /* Greenwich Mean */ - { "UT", 0 }, /* Universal Time */ - { "UTC", 0 }, /* Universal (Coordinated) */ - { "WET", 0 }, /* Western European */ - { "BST", 0 tDAYZONE }, /* British Summer */ - { "WAT", 60 }, /* West Africa */ - { "AST", 240 }, /* Atlantic Standard */ - { "ADT", 240 tDAYZONE }, /* Atlantic Daylight */ - { "EST", 300 }, /* Eastern Standard */ - { "EDT", 300 tDAYZONE }, /* Eastern Daylight */ - { "CST", 360 }, /* Central Standard */ - { "CDT", 360 tDAYZONE }, /* Central Daylight */ - { "MST", 420 }, /* Mountain Standard */ - { "MDT", 420 tDAYZONE }, /* Mountain Daylight */ - { "PST", 480 }, /* Pacific Standard */ - { "PDT", 480 tDAYZONE }, /* Pacific Daylight */ - { "YST", 540 }, /* Yukon Standard */ - { "YDT", 540 tDAYZONE }, /* Yukon Daylight */ - { "HST", 600 }, /* Hawaii Standard */ - { "HDT", 600 tDAYZONE }, /* Hawaii Daylight */ - { "CAT", 600 }, /* Central Alaska */ - { "AHST", 600 }, /* Alaska-Hawaii Standard */ - { "NT", 660 }, /* Nome */ /* spellchecker:disable-line */ - { "IDLW", 720 }, /* International Date Line West */ - { "CET", -60 }, /* Central European */ - { "MET", -60 }, /* Middle European */ - { "MEWT", -60 }, /* Middle European Winter */ - { "MEST", -60 tDAYZONE }, /* Middle European Summer */ - { "CEST", -60 tDAYZONE }, /* Central European Summer */ - { "MESZ", -60 tDAYZONE }, /* Middle European Summer */ - { "FWT", -60 }, /* French Winter */ - { "FST", -60 tDAYZONE }, /* French Summer */ - { "EET", -120 }, /* Eastern Europe, USSR Zone 1 */ + { "GMT", 0 }, /* Greenwich Mean */ + { "UT", 0 }, /* Universal Time */ + { "UTC", 0 }, /* Universal (Coordinated) */ + { "WET", 0 }, /* Western European */ + { "BST", 0 + tDAYZONE }, /* British Summer */ + { "WAT", 60 }, /* West Africa */ + { "AST", 240 }, /* Atlantic Standard */ + { "ADT", 240 + tDAYZONE }, /* Atlantic Daylight */ + { "EST", 300 }, /* Eastern Standard */ + { "EDT", 300 + tDAYZONE }, /* Eastern Daylight */ + { "CST", 360 }, /* Central Standard */ + { "CDT", 360 + tDAYZONE }, /* Central Daylight */ + { "MST", 420 }, /* Mountain Standard */ + { "MDT", 420 + tDAYZONE }, /* Mountain Daylight */ + { "PST", 480 }, /* Pacific Standard */ + { "PDT", 480 + tDAYZONE }, /* Pacific Daylight */ + { "YST", 540 }, /* Yukon Standard */ + { "YDT", 540 + tDAYZONE }, /* Yukon Daylight */ + { "HST", 600 }, /* Hawaii Standard */ + { "HDT", 600 + tDAYZONE }, /* Hawaii Daylight */ + { "CAT", 600 }, /* Central Alaska */ + { "AHST", 600 }, /* Alaska-Hawaii Standard */ + { "NT", 660 }, /* Nome */ /* spellchecker:disable-line */ + { "IDLW", 720 }, /* International Date Line West */ + { "CET", -60 }, /* Central European */ + { "MET", -60 }, /* Middle European */ + { "MEWT", -60 }, /* Middle European Winter */ + { "MEST", -60 + tDAYZONE }, /* Middle European Summer */ + { "CEST", -60 + tDAYZONE }, /* Central European Summer */ + { "MESZ", -60 + tDAYZONE }, /* Middle European Summer */ + { "FWT", -60 }, /* French Winter */ + { "FST", -60 + tDAYZONE }, /* French Summer */ + { "EET", -120 }, /* Eastern Europe, USSR Zone 1 */ { "WAST", -420 }, /* spellchecker:disable-line */ - /* West Australian Standard */ - { "WADT", -420 tDAYZONE }, /* West Australian Daylight */ - { "CCT", -480 }, /* China Coast, USSR Zone 7 */ - { "JST", -540 }, /* Japan Standard, USSR Zone 8 */ - { "EAST", -600 }, /* Eastern Australian Standard */ - { "EADT", -600 tDAYZONE }, /* Eastern Australian Daylight */ - { "GST", -600 }, /* Guam Standard, USSR Zone 9 */ - { "NZT", -720 }, /* New Zealand */ - { "NZST", -720 }, /* New Zealand Standard */ - { "NZDT", -720 tDAYZONE }, /* New Zealand Daylight */ - { "IDLE", -720 }, /* International Date Line East */ + /* West Australian Standard */ + { "WADT", -420 + tDAYZONE }, /* West Australian Daylight */ + { "CCT", -480 }, /* China Coast, USSR Zone 7 */ + { "JST", -540 }, /* Japan Standard, USSR Zone 8 */ + { "EAST", -600 }, /* Eastern Australian Standard */ + { "EADT", -600 + tDAYZONE }, /* Eastern Australian Daylight */ + { "GST", -600 }, /* Guam Standard, USSR Zone 9 */ + { "NZT", -720 }, /* New Zealand */ + { "NZST", -720 }, /* New Zealand Standard */ + { "NZDT", -720 + tDAYZONE }, /* New Zealand Daylight */ + { "IDLE", -720 }, /* International Date Line East */ /* Next up: Military timezone names. RFC822 allowed these, but (as noted in RFC 1123) had their signs wrong. Here we use the correct signs to match actual military usage. */ - { "A", 1 * 60 }, /* Alpha */ - { "B", 2 * 60 }, /* Bravo */ - { "C", 3 * 60 }, /* Charlie */ - { "D", 4 * 60 }, /* Delta */ - { "E", 5 * 60 }, /* Echo */ - { "F", 6 * 60 }, /* Foxtrot */ - { "G", 7 * 60 }, /* Golf */ - { "H", 8 * 60 }, /* Hotel */ - { "I", 9 * 60 }, /* India */ + { "A", 1 * 60 }, /* Alpha */ + { "B", 2 * 60 }, /* Bravo */ + { "C", 3 * 60 }, /* Charlie */ + { "D", 4 * 60 }, /* Delta */ + { "E", 5 * 60 }, /* Echo */ + { "F", 6 * 60 }, /* Foxtrot */ + { "G", 7 * 60 }, /* Golf */ + { "H", 8 * 60 }, /* Hotel */ + { "I", 9 * 60 }, /* India */ /* "J", Juliet is not used as a timezone, to indicate the observer's local time */ - { "K", 10 * 60 }, /* Kilo */ - { "L", 11 * 60 }, /* Lima */ - { "M", 12 * 60 }, /* Mike */ - { "N", -1 * 60 }, /* November */ - { "O", -2 * 60 }, /* Oscar */ - { "P", -3 * 60 }, /* Papa */ - { "Q", -4 * 60 }, /* Quebec */ - { "R", -5 * 60 }, /* Romeo */ - { "S", -6 * 60 }, /* Sierra */ - { "T", -7 * 60 }, /* Tango */ - { "U", -8 * 60 }, /* Uniform */ - { "V", -9 * 60 }, /* Victor */ - { "W", -10 * 60 }, /* Whiskey */ - { "X", -11 * 60 }, /* X-ray */ - { "Y", -12 * 60 }, /* Yankee */ - { "Z", 0 }, /* Zulu, zero meridian, a.k.a. UTC */ + { "K", 10 * 60 }, /* Kilo */ + { "L", 11 * 60 }, /* Lima */ + { "M", 12 * 60 }, /* Mike */ + { "N", -1 * 60 }, /* November */ + { "O", -2 * 60 }, /* Oscar */ + { "P", -3 * 60 }, /* Papa */ + { "Q", -4 * 60 }, /* Quebec */ + { "R", -5 * 60 }, /* Romeo */ + { "S", -6 * 60 }, /* Sierra */ + { "T", -7 * 60 }, /* Tango */ + { "U", -8 * 60 }, /* Uniform */ + { "V", -9 * 60 }, /* Victor */ + { "W", -10 * 60 }, /* Whiskey */ + { "X", -11 * 60 }, /* X-ray */ + { "Y", -12 * 60 }, /* Yankee */ + { "Z", 0 }, /* Zulu, zero meridian, a.k.a. UTC */ }; /* returns: diff --git a/lib/setopt.c b/lib/setopt.c index 781151512c..9db5ce33be 100644 --- a/lib/setopt.c +++ b/lib/setopt.c @@ -189,8 +189,8 @@ static CURLcode setstropt_interface(char *option, char **devp, } #ifdef USE_SSL -#define C_SSLVERSION_VALUE(x) (x & 0xffff) -#define C_SSLVERSION_MAX_VALUE(x) ((unsigned long)x & 0xffff0000) +#define C_SSLVERSION_VALUE(x) ((x) & 0xffff) +#define C_SSLVERSION_MAX_VALUE(x) ((unsigned long)(x) & 0xffff0000) #endif static CURLcode protocol2num(const char *str, curl_prot_t *val) diff --git a/lib/sigpipe.h b/lib/sigpipe.h index a906b27037..b489796953 100644 --- a/lib/sigpipe.h +++ b/lib/sigpipe.h @@ -88,10 +88,10 @@ static CURL_INLINE void sigpipe_apply(struct Curl_easy *data, #else /* !HAVE_SIGACTION || USE_SO_NOSIGPIPE */ /* for systems without sigaction or where SO_NOSIGPIPE is used. */ -#define sigpipe_ignore(x, y) do { (void)x; (void)y; } while(0) -#define sigpipe_apply(x, y) do { (void)x; (void)y; } while(0) -#define sigpipe_init(x) do { (void)x; } while(0) -#define sigpipe_restore(x) do { (void)x; } while(0) +#define sigpipe_ignore(x, y) do { (void)(x); (void)(y); } while(0) +#define sigpipe_apply(x, y) do { (void)(x); (void)(y); } while(0) +#define sigpipe_init(x) do { (void)(x); } while(0) +#define sigpipe_restore(x) do { (void)(x); } while(0) struct Curl_sigpipe_ctx { bool dummy; diff --git a/lib/telnet.c b/lib/telnet.c index c89e94e9f9..678fe656a3 100644 --- a/lib/telnet.c +++ b/lib/telnet.c @@ -58,20 +58,20 @@ #define SUBBUFSIZE 512 -#define CURL_SB_CLEAR(x) x->subpointer = x->subbuffer -#define CURL_SB_TERM(x) \ - do { \ - x->subend = x->subpointer; \ - CURL_SB_CLEAR(x); \ +#define CURL_SB_CLEAR(x) x->subpointer = (x)->subbuffer +#define CURL_SB_TERM(x) \ + do { \ + (x)->subend = (x)->subpointer; \ + CURL_SB_CLEAR(x); \ } while(0) -#define CURL_SB_ACCUM(x, c) \ - do { \ - if(x->subpointer < (x->subbuffer + sizeof(x->subbuffer))) \ - *x->subpointer++ = (c); \ +#define CURL_SB_ACCUM(x, c) \ + do { \ + if((x)->subpointer < ((x)->subbuffer + sizeof((x)->subbuffer))) \ + *(x)->subpointer++ = (c); \ } while(0) -#define CURL_SB_GET(x) ((*x->subpointer++) & 0xff) -#define CURL_SB_LEN(x) (x->subend - x->subpointer) +#define CURL_SB_GET(x) ((*(x)->subpointer++) & 0xff) +#define CURL_SB_LEN(x) ((x)->subend - (x)->subpointer) /* For posterity: #define CURL_SB_PEEK(x) ((*x->subpointer)&0xff) diff --git a/lib/uint-hash.c b/lib/uint-hash.c index e23d249d05..2377840200 100644 --- a/lib/uint-hash.c +++ b/lib/uint-hash.c @@ -107,7 +107,7 @@ static void uint32_hash_elem_link(struct uint_hash *h, ++h->size; } -#define CURL_UINT32_HASH_SLOT(h, id) h->table[uint32_hash_hash(id, h->slots)] +#define CURL_UINT32_HASH_SLOT(h, id) h->table[uint32_hash_hash(id, (h)->slots)] #define CURL_UINT32_HASH_SLOT_ADDR(h, id) &CURL_UINT32_HASH_SLOT(h, id) bool Curl_uint32_hash_set(struct uint_hash *h, uint32_t id, void *value) diff --git a/lib/url.c b/lib/url.c index 8b42aebade..7e7408a5d7 100644 --- a/lib/url.c +++ b/lib/url.c @@ -1235,7 +1235,7 @@ static bool url_match_auth_nego(struct connectdata *conn, return TRUE; } #else -#define url_match_auth_nego(c, m) ((void)c, (void)m, TRUE) +#define url_match_auth_nego(c, m) ((void)(c), (void)(m), TRUE) #endif static bool url_match_conn(struct connectdata *conn, void *userdata) diff --git a/lib/urlapi.c b/lib/urlapi.c index 18cdb43745..0e783f4a29 100644 --- a/lib/urlapi.c +++ b/lib/urlapi.c @@ -37,10 +37,10 @@ #ifdef _WIN32 /* MS-DOS/Windows style drive prefix, eg c: in c:foo */ -#define STARTS_WITH_DRIVE_PREFIX(str) \ - ((('a' <= str[0] && str[0] <= 'z') || \ - ('A' <= str[0] && str[0] <= 'Z')) && \ - (str[1] == ':')) +#define STARTS_WITH_DRIVE_PREFIX(str) \ + ((('a' <= (str)[0] && (str)[0] <= 'z') || \ + ('A' <= (str)[0] && (str)[0] <= 'Z')) && \ + ((str)[1] == ':')) #endif /* MS-DOS/Windows style drive prefix, optionally with @@ -474,7 +474,7 @@ static CURLUcode hostname_check(struct Curl_URL *u, char *hostname, * Returns the host type. */ -#define HOST_ERROR -1 /* out of memory */ +#define HOST_ERROR (-1) /* out of memory */ #define HOST_NAME 1 #define HOST_IPV4 2 @@ -1300,9 +1300,9 @@ void curl_url_cleanup(CURLU *u) #define DUP(dest, src, name) \ do { \ - if(src->name) { \ - dest->name = curlx_strdup(src->name); \ - if(!dest->name) \ + if((src)->name) { \ + (dest)->name = curlx_strdup((src)->name); \ + if(!(dest)->name) \ goto fail; \ } \ } while(0) diff --git a/lib/urldata.h b/lib/urldata.h index e87e815d86..2ca2233c56 100644 --- a/lib/urldata.h +++ b/lib/urldata.h @@ -328,7 +328,7 @@ typedef enum { #ifdef CURL_DISABLE_PROXY #define CONN_IS_PROXIED(x) 0 #else -#define CONN_IS_PROXIED(x) x->bits.proxy +#define CONN_IS_PROXIED(x) (x)->bits.proxy #endif /* diff --git a/src/tool_cb_wrt.c b/src/tool_cb_wrt.c index cfeb06d5a4..1d2b81ea7c 100644 --- a/src/tool_cb_wrt.c +++ b/src/tool_cb_wrt.c @@ -29,9 +29,9 @@ #include "tool_operate.h" #ifdef _WIN32 -#define OPENMODE _S_IREAD | _S_IWRITE +#define OPENMODE (_S_IREAD | _S_IWRITE) #else -#define OPENMODE S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH +#define OPENMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) #endif /* create/open a local file for writing, return TRUE on success */ diff --git a/src/tool_parsecfg.c b/src/tool_parsecfg.c index 01594644fb..9cecaaa2f4 100644 --- a/src/tool_parsecfg.c +++ b/src/tool_parsecfg.c @@ -33,7 +33,7 @@ /* only acknowledge colon or equals as separators if the option was not specified with an initial dash! */ -#define ISSEP(x, dash) (!dash && (((x) == '=') || ((x) == ':'))) +#define ISSEP(x, dash) (!(dash) && (((x) == '=') || ((x) == ':'))) /* * Copies the string from line to the param dynbuf, unquoting backslash-quoted diff --git a/src/tool_setopt.c b/src/tool_setopt.c index 003b772328..750ef169d3 100644 --- a/src/tool_setopt.c +++ b/src/tool_setopt.c @@ -175,7 +175,7 @@ static const struct NameValue setopt_nv_CURLNONZERODEFAULTS[] = { /* Escape string to C string syntax. Return NULL if out of memory. */ #define MAX_STRING_LENGTH_OUTPUT 2000 -#define ZERO_TERMINATED -1 +#define ZERO_TERMINATED (-1) static char *c_escape(const char *str, curl_off_t len) { diff --git a/src/tool_setopt.h b/src/tool_setopt.h index e990f08a81..bb85ae7088 100644 --- a/src/tool_setopt.h +++ b/src/tool_setopt.h @@ -134,7 +134,7 @@ CURLcode tool_setopt_ptr(CURL *curl, const char *name, CURLoption tag, ...); #define my_setopt_slist(x, y, z) curl_easy_setopt(x, y, z) #define my_setopt_SSLVERSION(x, y, z) curl_easy_setopt(x, y, z) #define my_setopt_enum(x, y, z) curl_easy_setopt(x, y, z) -#define my_setopt_bitmask(x, y, z) curl_easy_setopt(x, y, (long)z) +#define my_setopt_bitmask(x, y, z) curl_easy_setopt(x, y, (long)(z)) #define MY_SETOPT_STR(x, y, z) \ do { \ diff --git a/src/tool_vms.h b/src/tool_vms.h index 89ea31ee15..b459a25ee8 100644 --- a/src/tool_vms.h +++ b/src/tool_vms.h @@ -40,8 +40,11 @@ void vms_special_exit(int code, int vms_show); #undef exit #define exit(__code) vms_special_exit(__code, 0) -#define VMS_STS(c, f, e, s) \ - (((c & 0xF) << 28) | ((f & 0xFFF) << 16) | ((e & 0x1FFF) < 3) | (s & 7)) +#define VMS_STS(c, f, e, s) \ + ((((c) & 0xF) << 28) | \ + (((f) & 0xFFF) << 16) | \ + (((e) & 0x1FFF) < 3) | \ + ((s) & 7)) #define VMSSTS_HIDE VMS_STS(1, 0, 0, 0) #endif /* __VMS */ diff --git a/src/var.c b/src/var.c index fbb35a7d01..7fb51d656e 100644 --- a/src/var.c +++ b/src/var.c @@ -59,7 +59,7 @@ static const struct tool_var *varcontent(const char *name, size_t nlen) #define ENDOFFUNC(x) (((x) == '}') || ((x) == ':')) #define FUNCMATCH(ptr, name, len) \ - (!strncmp(ptr, name, len) && ENDOFFUNC(ptr[len])) + (!strncmp(ptr, name, len) && ENDOFFUNC((ptr)[len])) #define FUNC_TRIM "trim" #define FUNC_TRIM_LEN (sizeof(FUNC_TRIM) - 1) diff --git a/tests/libtest/first.h b/tests/libtest/first.h index af4be59ea1..8db531be1f 100644 --- a/tests/libtest/first.h +++ b/tests/libtest/first.h @@ -149,7 +149,7 @@ void ws_close(CURL *curl); /* just close the connection */ #define exe_easy_init(A, Y, Z) \ do { \ - A = curl_easy_init(); \ + (A) = curl_easy_init(); \ if(!(A)) { \ curl_mfprintf(stderr, "%s:%d curl_easy_init() failed\n", Y, Z); \ result = TEST_ERR_EASY_INIT; \ @@ -173,7 +173,7 @@ void ws_close(CURL *curl); /* just close the connection */ #define exe_multi_init(A, Y, Z) \ do { \ - A = curl_multi_init(); \ + (A) = curl_multi_init(); \ if(!(A)) { \ curl_mfprintf(stderr, "%s:%d curl_multi_init() failed\n", Y, Z); \ result = TEST_ERR_MULTI; \ @@ -499,7 +499,7 @@ void ws_close(CURL *curl); /* just close the connection */ tv_test_start = curlx_now(); \ } while(0) -#define TEST_HANG_TIMEOUT 60 * 1000 /* global default */ +#define TEST_HANG_TIMEOUT (60 * 1000) /* global default */ #define exe_test_timedout(T, Y, Z) \ do { \ @@ -508,7 +508,7 @@ void ws_close(CURL *curl); /* just close the connection */ curl_mfprintf(stderr, \ "%s:%d ABORTING TEST, since it seems " \ "that it would have run forever (%ld ms > %ld ms)\n", \ - Y, Z, (long)timediff, (long)(TEST_HANG_TIMEOUT)); \ + Y, Z, (long)timediff, (long)TEST_HANG_TIMEOUT); \ result = TEST_ERR_RUNS_FOREVER; \ } \ } while(0) diff --git a/tests/libtest/lib2405.c b/tests/libtest/lib2405.c index a87ff0b5e5..f0a3b9aded 100644 --- a/tests/libtest/lib2405.c +++ b/tests/libtest/lib2405.c @@ -46,7 +46,7 @@ curl_mfprintf(stderr, "test failed with code: %d\n", result); \ goto test_cleanup; \ } \ - else if(fd_count != expected_fds) { \ + else if(fd_count != (expected_fds)) { \ curl_mfprintf(stderr, "Max number of waitfds: %u not as expected: %u\n", \ fd_count, expected_fds); \ result = TEST_ERR_FAILURE; \ diff --git a/tests/libtest/lib557.c b/tests/libtest/lib557.c index edf7590732..56eed1a57f 100644 --- a/tests/libtest/lib557.c +++ b/tests/libtest/lib557.c @@ -1322,7 +1322,7 @@ static int test_weird_arguments(void) } /* DBL_MAX value from Linux */ -#define MAXIMIZE -1.7976931348623157081452E+308 +#define MAXIMIZE (-1.7976931348623157081452E+308) static int test_float_formatting(void) { diff --git a/tests/libtest/mk-lib1521.pl b/tests/libtest/mk-lib1521.pl index 3430ca1f19..72bfce4294 100755 --- a/tests/libtest/mk-lib1521.pl +++ b/tests/libtest/mk-lib1521.pl @@ -214,9 +214,9 @@ struct t1521_testdata { #define LO $minlong #define HI $maxlong -#define OFF_LO (curl_off_t) LO -#define OFF_HI (curl_off_t) $maxofft -#define OFF_NO (curl_off_t) 0 +#define OFF_LO ((curl_off_t)(LO)) +#define OFF_HI ((curl_off_t)($maxofft)) +#define OFF_NO ((curl_off_t)0) static size_t writecb(char *buffer, size_t size, size_t nitems, void *outstream) @@ -345,7 +345,9 @@ static bool bad_neg(int check) /* macro to check the first setopt of an option which then is allowed to get a non-existing function return code back */ -#define present(x) ((x != CURLE_NOT_BUILT_IN) && (x != CURLE_UNKNOWN_OPTION)) +#define present(x) \\ + (((x) != CURLE_NOT_BUILT_IN) && \\ + ((x) != CURLE_UNKNOWN_OPTION)) static CURLcode test_lib1521(const char *URL) { diff --git a/tests/libtest/unitcheck.h b/tests/libtest/unitcheck.h index 5bb254e49c..fa71757fb9 100644 --- a/tests/libtest/unitcheck.h +++ b/tests/libtest/unitcheck.h @@ -44,12 +44,12 @@ #define verify_memory(dynamic, check, len) \ do { \ - if(dynamic && memcmp(dynamic, check, len)) { \ + if((dynamic) && memcmp(dynamic, check, len)) { \ curl_mfprintf(stderr, "%s:%d Memory buffer FAILED match size %d. " \ "'%s' is not\n", __FILE__, __LINE__, len, \ - hexdump((const unsigned char *)check, len)); \ + hexdump((const unsigned char *)(check), len)); \ curl_mfprintf(stderr, "%s:%d the same as '%s'\n", __FILE__, __LINE__, \ - hexdump((const unsigned char *)dynamic, len)); \ + hexdump((const unsigned char *)(dynamic), len)); \ unitfail++; \ } \ } while(0) @@ -116,5 +116,5 @@ unit_test_abort: \ goto unit_test_abort; /* avoid warning */ \ } \ unit_test_abort: \ - stopfunc; \ + (stopfunc); \ return (CURLcode)unitfail; diff --git a/tests/server/first.h b/tests/server/first.h index bb88771175..1de5f43a64 100644 --- a/tests/server/first.h +++ b/tests/server/first.h @@ -112,8 +112,8 @@ typedef union { } srvr_sockaddr_union_t; /* getpart */ -#define GPE_NO_BUFFER_SPACE -2 -#define GPE_OUT_OF_MEMORY -1 +#define GPE_NO_BUFFER_SPACE (-2) +#define GPE_OUT_OF_MEMORY (-1) #define GPE_OK 0 #define GPE_END_OF_FILE 1 diff --git a/tests/server/tftpd.c b/tests/server/tftpd.c index d4f2b01601..1bf6433e4b 100644 --- a/tests/server/tftpd.c +++ b/tests/server/tftpd.c @@ -146,8 +146,8 @@ struct bf { tftphdr_storage_t buf; /* room for data packet */ }; -#define BF_ALLOC -3 /* allocated but not yet filled */ -#define BF_FREE -2 /* free */ +#define BF_ALLOC (-3) /* allocated but not yet filled */ +#define BF_FREE (-2) /* free */ #define opcode_RRQ 1 #define opcode_WRQ 2