diff --git a/.clang-tidy.yml b/.clang-tidy.yml index 25eb4ee9e9..9ccbbf83d9 100644 --- a/.clang-tidy.yml +++ b/.clang-tidy.yml @@ -18,6 +18,7 @@ Checks: - misc-header-include-cycle - portability-* - readability-duplicate-include + - readability-math-missing-parentheses - readability-named-parameter - readability-redundant-control-flow - readability-redundant-preprocessor diff --git a/lib/cf-h1-proxy.c b/lib/cf-h1-proxy.c index f29c8f0865..c51ae26d9e 100644 --- a/lib/cf-h1-proxy.c +++ b/lib/cf-h1-proxy.c @@ -340,8 +340,8 @@ static CURLcode on_resp_header(struct Curl_cfilter *cf, ISDIGIT(header[9]) && ISDIGIT(header[10]) && ISDIGIT(header[11]) && !ISDIGIT(header[12])) { /* store the HTTP code from the proxy */ - data->info.httpproxycode = k->httpcode = (header[9] - '0') * 100 + - (header[10] - '0') * 10 + (header[11] - '0'); + data->info.httpproxycode = k->httpcode = ((header[9] - '0') * 100) + + ((header[10] - '0') * 10) + (header[11] - '0'); } return result; } diff --git a/lib/curl_ntlm_core.c b/lib/curl_ntlm_core.c index 2603951f23..4a9433b293 100644 --- a/lib/curl_ntlm_core.c +++ b/lib/curl_ntlm_core.c @@ -399,7 +399,7 @@ static void ascii_to_unicode_le(unsigned char *dest, const char *src, size_t i; for(i = 0; i < srclen; i++) { dest[2 * i] = (unsigned char)src[i]; - dest[2 * i + 1] = '\0'; + dest[(2 * i) + 1] = '\0'; } } @@ -492,7 +492,7 @@ static void ascii_uppercase_to_unicode_le(unsigned char *dest, size_t i; for(i = 0; i < srclen; i++) { dest[2 * i] = (unsigned char)(Curl_raw_toupper(src[i])); - dest[2 * i + 1] = '\0'; + dest[(2 * i) + 1] = '\0'; } } diff --git a/lib/curlx/base64.c b/lib/curlx/base64.c index d869975e67..a7a6703099 100644 --- a/lib/curlx/base64.c +++ b/lib/curlx/base64.c @@ -182,7 +182,7 @@ static CURLcode base64_encode(const char *table64, if(insize > CURL_MAX_BASE64_INPUT) return CURLE_TOO_LARGE; - base64data = output = curlx_malloc((insize + 2) / 3 * 4 + 1); + base64data = output = curlx_malloc(((insize + 2) / 3 * 4) + 1); if(!output) return CURLE_OUT_OF_MEMORY; diff --git a/lib/curlx/strparse.c b/lib/curlx/strparse.c index 8a2523fe79..138b3df125 100644 --- a/lib/curlx/strparse.c +++ b/lib/curlx/strparse.c @@ -172,7 +172,7 @@ static int str_num_base(const char **linep, curl_off_t *nump, curl_off_t max, /* special-case low max scenario because check needs to be different */ do { int n = curlx_hexval(*p++); - num = num * base + n; + num = (num * base) + n; if(num > max) return STRE_OVERFLOW; } while(valid_digit(*p, m)); @@ -182,7 +182,7 @@ static int str_num_base(const char **linep, curl_off_t *nump, curl_off_t max, int n = curlx_hexval(*p++); if(num > ((max - n) / base)) return STRE_OVERFLOW; - num = num * base + n; + num = (num * base) + n; } while(valid_digit(*p, m)); } *nump = num; diff --git a/lib/curlx/timeval.c b/lib/curlx/timeval.c index 0f0883d74a..ae67e9bb42 100644 --- a/lib/curlx/timeval.c +++ b/lib/curlx/timeval.c @@ -191,7 +191,7 @@ timediff_t curlx_ptimediff_ms(const struct curltime *newer, return TIMEDIFF_T_MAX; else if(diff <= (TIMEDIFF_T_MIN / 1000)) return TIMEDIFF_T_MIN; - return diff * 1000 + (newer->tv_usec - older->tv_usec) / 1000; + return (diff * 1000) + ((newer->tv_usec - older->tv_usec) / 1000); } @@ -212,7 +212,7 @@ timediff_t curlx_timediff_ceil_ms(struct curltime newer, return TIMEDIFF_T_MAX; else if(diff <= (TIMEDIFF_T_MIN / 1000)) return TIMEDIFF_T_MIN; - return diff * 1000 + (newer.tv_usec - older.tv_usec + 999) / 1000; + return (diff * 1000) + ((newer.tv_usec - older.tv_usec + 999) / 1000); } /* @@ -227,7 +227,7 @@ timediff_t curlx_ptimediff_us(const struct curltime *newer, return TIMEDIFF_T_MAX; else if(diff <= (TIMEDIFF_T_MIN / 1000000)) return TIMEDIFF_T_MIN; - return diff * 1000000 + newer->tv_usec - older->tv_usec; + return (diff * 1000000) + newer->tv_usec - older->tv_usec; } timediff_t curlx_timediff_us(struct curltime newer, struct curltime older) diff --git a/lib/escape.c b/lib/escape.c index afdf18c1b4..be44e97156 100644 --- a/lib/escape.c +++ b/lib/escape.c @@ -63,7 +63,7 @@ char *curl_easy_escape(CURL *data, const char *string, int inlength) if(length > SIZE_MAX / 16) return NULL; - curlx_dyn_init(&d, length * 3 + 1); + curlx_dyn_init(&d, (length * 3) + 1); while(length--) { /* treat the characters unsigned */ diff --git a/lib/ftp.c b/lib/ftp.c index b13da7abbd..fd10b07629 100644 --- a/lib/ftp.c +++ b/lib/ftp.c @@ -2496,7 +2496,7 @@ static CURLcode ftp_state_port_resp(struct Curl_easy *data, static int twodigit(const char *p) { - return (p[0] - '0') * 10 + (p[1] - '0'); + return ((p[0] - '0') * 10) + (p[1] - '0'); } static bool ftp_213_date(const char *p, int *year, int *month, int *day, @@ -2505,7 +2505,7 @@ static bool ftp_213_date(const char *p, int *year, int *month, int *day, size_t len = strlen(p); if(len < 14) return FALSE; - *year = twodigit(&p[0]) * 100 + twodigit(&p[2]); + *year = (twodigit(&p[0]) * 100) + twodigit(&p[2]); *month = twodigit(&p[4]); *day = twodigit(&p[6]); *hour = twodigit(&p[8]); diff --git a/lib/hmac.c b/lib/hmac.c index 10d7c1d03b..028b476c77 100644 --- a/lib/hmac.c +++ b/lib/hmac.c @@ -52,7 +52,7 @@ struct HMAC_context *Curl_HMAC_init(const struct HMAC_params *hashparams, unsigned char b; /* Create HMAC context. */ - i = sizeof(*ctxt) + 2 * hashparams->ctxtsize + hashparams->resultlen; + i = sizeof(*ctxt) + (2 * hashparams->ctxtsize) + hashparams->resultlen; ctxt = curlx_malloc(i); if(!ctxt) diff --git a/lib/http.c b/lib/http.c index afad728b50..183a39966e 100644 --- a/lib/http.c +++ b/lib/http.c @@ -4232,7 +4232,7 @@ static CURLcode http_rw_hd(struct Curl_easy *data, k->httpversion = (unsigned char)(10 + (p[1] - '0')); p += 3; if(ISDIGIT(p[0]) && ISDIGIT(p[1]) && ISDIGIT(p[2])) { - k->httpcode = (p[0] - '0') * 100 + (p[1] - '0') * 10 + + k->httpcode = ((p[0] - '0') * 100) + ((p[1] - '0') * 10) + (p[2] - '0'); /* RFC 9112 requires a single space following the status code, but the browsers do not so let's not insist */ @@ -4252,7 +4252,7 @@ static CURLcode http_rw_hd(struct Curl_easy *data, k->httpversion = (unsigned char)((*p - '0') * 10); p += 2; if(ISDIGIT(p[0]) && ISDIGIT(p[1]) && ISDIGIT(p[2])) { - k->httpcode = (p[0] - '0') * 100 + (p[1] - '0') * 10 + + k->httpcode = ((p[0] - '0') * 100) + ((p[1] - '0') * 10) + (p[2] - '0'); p += 3; if(!ISBLANK(*p)) diff --git a/lib/http_aws_sigv4.c b/lib/http_aws_sigv4.c index bb00bb5b49..40edcf315c 100644 --- a/lib/http_aws_sigv4.c +++ b/lib/http_aws_sigv4.c @@ -53,7 +53,7 @@ #define TIMESTAMP_SIZE 17 /* hex-encoded with trailing null */ -#define SHA256_HEX_LENGTH (2 * CURL_SHA256_DIGEST_LENGTH + 1) +#define SHA256_HEX_LENGTH ((2 * CURL_SHA256_DIGEST_LENGTH) + 1) #define MAX_QUERY_COMPONENTS 128 @@ -745,8 +745,10 @@ UNITTEST CURLcode canon_query(const char *query, struct dynbuf *dq) in_key_len = offset - in_key; } - curlx_dyn_init(&encoded_query_array[index].key, query_part_len * 3 + 1); - curlx_dyn_init(&encoded_query_array[index].value, query_part_len * 3 + 1); + curlx_dyn_init(&encoded_query_array[index].key, + (query_part_len * 3) + 1); + curlx_dyn_init(&encoded_query_array[index].value, + (query_part_len * 3) + 1); counted_query_components++; /* Decode/encode the key */ diff --git a/lib/md4.c b/lib/md4.c index 55e9b01416..bf1dc0d25f 100644 --- a/lib/md4.c +++ b/lib/md4.c @@ -218,12 +218,12 @@ typedef struct md4_ctx MD4_CTX; #define MD4_SET(n) (*(const uint32_t *)(const void *)&ptr[(n) * 4]) #define MD4_GET(n) MD4_SET(n) #else -#define MD4_SET(n) (ctx->block[(n)] = \ - (uint32_t)ptr[(n) * 4] | \ - ((uint32_t)ptr[(n) * 4 + 1] << 8) | \ - ((uint32_t)ptr[(n) * 4 + 2] << 16) | \ - ((uint32_t)ptr[(n) * 4 + 3] << 24)) -#define MD4_GET(n) (ctx->block[(n)]) +#define MD4_SET(n) (ctx->block[n] = \ + (uint32_t)ptr[(n) * 4] | \ + ((uint32_t)ptr[((n) * 4) + 1] << 8) | \ + ((uint32_t)ptr[((n) * 4) + 2] << 16) | \ + ((uint32_t)ptr[((n) * 4) + 3] << 24)) +#define MD4_GET(n) ctx->block[n] #endif /* diff --git a/lib/md5.c b/lib/md5.c index 464088b1b1..e76863dc22 100644 --- a/lib/md5.c +++ b/lib/md5.c @@ -299,12 +299,12 @@ typedef struct md5_ctx my_md5_ctx; #define MD5_SET(n) (*(const uint32_t *)(const void *)&ptr[(n) * 4]) #define MD5_GET(n) MD5_SET(n) #else -#define MD5_SET(n) (ctx->block[(n)] = \ - (uint32_t)ptr[(n) * 4] | \ - ((uint32_t)ptr[(n) * 4 + 1] << 8) | \ - ((uint32_t)ptr[(n) * 4 + 2] << 16) | \ - ((uint32_t)ptr[(n) * 4 + 3] << 24)) -#define MD5_GET(n) (ctx->block[(n)]) +#define MD5_SET(n) (ctx->block[n] = \ + (uint32_t)ptr[(n) * 4] | \ + ((uint32_t)ptr[((n) * 4) + 1] << 8) | \ + ((uint32_t)ptr[((n) * 4) + 2] << 16) | \ + ((uint32_t)ptr[((n) * 4) + 3] << 24)) +#define MD5_GET(n) ctx->block[n] #endif /* diff --git a/lib/mime.c b/lib/mime.c index fdac2e0f41..05b24435d4 100644 --- a/lib/mime.c +++ b/lib/mime.c @@ -426,7 +426,7 @@ static curl_off_t encoder_base64_size(curl_mimepart *part) size = 4 * (1 + (size - 1) / 3); /* Effective character count must include CRLFs. */ - return size + 2 * ((size - 1) / MAX_ENCODED_LINE_LENGTH); + return size + (2 * ((size - 1) / MAX_ENCODED_LINE_LENGTH)); } /* Quoted-printable lookahead. diff --git a/lib/parsedate.c b/lib/parsedate.c index 3775cb6e1d..1eec38a048 100644 --- a/lib/parsedate.c +++ b/lib/parsedate.c @@ -279,9 +279,10 @@ static time_t time2epoch(int sec, int min, int hour, int leap_days = year - (mon <= 1); leap_days = ((leap_days / 4) - (leap_days / 100) + (leap_days / 400) - (1969 / 4) + (1969 / 100) - (1969 / 400)); - return ((((time_t)(year - 1970) * 365 - + leap_days + month_days_cumulative[mon] + mday - 1) * 24 - + hour) * 60 + min) * 60 + sec; + return ((((((((time_t)(year - 1970) * 365) + + leap_days + month_days_cumulative[mon] + mday - 1) * 24) + + hour) * 60) + + min) * 60) + sec; } /* Returns the value of a single-digit or two-digit decimal number, return @@ -292,7 +293,7 @@ static int oneortwodigit(const char *date, const char **endp) int num = date[0] - '0'; if(ISDIGIT(date[1])) { *endp = &date[2]; - return num * 10 + (date[1] - '0'); + return (num * 10) + (date[1] - '0'); } *endp = &date[1]; return num; @@ -445,7 +446,7 @@ static int parsedate(const char *date, time_t *output) /* 8 digits, no year, month or day yet. This is YYYYMMDD */ found = TRUE; yearnum = val / 10000; - monnum = (val % 10000) / 100 - 1; /* month is 0 - 11 */ + monnum = ((val % 10000) / 100) - 1; /* month is 0 - 11 */ mdaynum = val % 100; } diff --git a/lib/pop3.c b/lib/pop3.c index fdb09f2320..de704d11e1 100644 --- a/lib/pop3.c +++ b/lib/pop3.c @@ -557,7 +557,7 @@ static CURLcode pop3_perform_apop(struct Curl_easy *data, size_t i; struct MD5_context *ctxt; unsigned char digest[MD5_DIGEST_LEN]; - char secret[2 * MD5_DIGEST_LEN + 1]; + char secret[(2 * MD5_DIGEST_LEN) + 1]; if(!pop3c) return CURLE_FAILED_INIT; diff --git a/lib/smb.c b/lib/smb.c index 09d09a3a99..8e76edc83d 100644 --- a/lib/smb.c +++ b/lib/smb.c @@ -548,7 +548,7 @@ static CURLcode smb_recv_message(struct Curl_easy *data, if(nbt_size >= msg_size + 1) { /* Add the word count */ - msg_size += 1 + ((unsigned char)buf[msg_size]) * sizeof(unsigned short); + msg_size += 1 + (((unsigned char)buf[msg_size]) * sizeof(unsigned short)); if(nbt_size >= msg_size + sizeof(unsigned short)) { /* Add the byte count */ msg_size += sizeof(unsigned short) + diff --git a/lib/urlapi.c b/lib/urlapi.c index 0e783f4a29..c59f239756 100644 --- a/lib/urlapi.c +++ b/lib/urlapi.c @@ -1877,7 +1877,7 @@ CURLUcode curl_url_set(CURLU *u, CURLUPart what, { const char *newp; struct dynbuf enc; - curlx_dyn_init(&enc, nalloc * 3 + 1 + leadingslash); + curlx_dyn_init(&enc, (nalloc * 3) + 1 + leadingslash); if(leadingslash && (part[0] != '/')) { CURLcode result = curlx_dyn_addn(&enc, "/", 1); diff --git a/lib/vauth/digest.c b/lib/vauth/digest.c index 1a5f6ffde2..1bbed79392 100644 --- a/lib/vauth/digest.c +++ b/lib/vauth/digest.c @@ -341,9 +341,9 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data, struct MD5_context *ctxt; char *response = NULL; unsigned char digest[MD5_DIGEST_LEN]; - char HA1_hex[2 * MD5_DIGEST_LEN + 1]; - char HA2_hex[2 * MD5_DIGEST_LEN + 1]; - char resp_hash_hex[2 * MD5_DIGEST_LEN + 1]; + char HA1_hex[(2 * MD5_DIGEST_LEN) + 1]; + char HA2_hex[(2 * MD5_DIGEST_LEN) + 1]; + char resp_hash_hex[(2 * MD5_DIGEST_LEN) + 1]; char nonce[64]; char realm[128]; char algorithm[64]; diff --git a/lib/vauth/ntlm.c b/lib/vauth/ntlm.c index 205ce6c06d..b50cfdd681 100644 --- a/lib/vauth/ntlm.c +++ b/lib/vauth/ntlm.c @@ -398,7 +398,7 @@ static void unicodecpy(unsigned char *dest, const char *src, size_t length) size_t i; for(i = 0; i < length; i++) { dest[2 * i] = (unsigned char)src[i]; - dest[2 * i + 1] = '\0'; + dest[(2 * i) + 1] = '\0'; } } diff --git a/lib/vquic/curl_ngtcp2.c b/lib/vquic/curl_ngtcp2.c index 123eb19b3d..ac8e4f35c9 100644 --- a/lib/vquic/curl_ngtcp2.c +++ b/lib/vquic/curl_ngtcp2.c @@ -391,8 +391,8 @@ static void pktx_update_time(struct Curl_easy *data, const struct curltime *pnow = Curl_pgrs_now(data); vquic_ctx_update_time(&ctx->q, pnow); - pktx->ts = (ngtcp2_tstamp)pnow->tv_sec * NGTCP2_SECONDS + - (ngtcp2_tstamp)pnow->tv_usec * NGTCP2_MICROSECONDS; + pktx->ts = ((ngtcp2_tstamp)pnow->tv_sec * NGTCP2_SECONDS) + + ((ngtcp2_tstamp)pnow->tv_usec * NGTCP2_MICROSECONDS); } static void pktx_init(struct pkt_io_ctx *pktx, @@ -406,8 +406,8 @@ static void pktx_init(struct pkt_io_ctx *pktx, pktx->data = data; ngtcp2_path_storage_zero(&pktx->ps); vquic_ctx_set_time(&ctx->q, pnow); - pktx->ts = (ngtcp2_tstamp)pnow->tv_sec * NGTCP2_SECONDS + - (ngtcp2_tstamp)pnow->tv_usec * NGTCP2_MICROSECONDS; + pktx->ts = ((ngtcp2_tstamp)pnow->tv_sec * NGTCP2_SECONDS) + + ((ngtcp2_tstamp)pnow->tv_usec * NGTCP2_MICROSECONDS); } static int cb_h3_acked_req_body(nghttp3_conn *conn, int64_t stream_id, diff --git a/lib/vtls/keylog.c b/lib/vtls/keylog.c index 51b26d2d3f..0206e32cf8 100644 --- a/lib/vtls/keylog.c +++ b/lib/vtls/keylog.c @@ -107,8 +107,9 @@ bool Curl_tls_keylog_write(const char *label, const unsigned char *secret, size_t secretlen) { size_t pos, i; - unsigned char line[KEYLOG_LABEL_MAXLEN + 1 + 2 * CLIENT_RANDOM_SIZE + 1 + - 2 * SECRET_MAXLEN + 1 + 1]; + unsigned char line[KEYLOG_LABEL_MAXLEN + 1 + + (2 * CLIENT_RANDOM_SIZE) + 1 + + (2 * SECRET_MAXLEN) + 1 + 1]; if(!keylog_file_fp) { return FALSE; diff --git a/lib/vtls/mbedtls.c b/lib/vtls/mbedtls.c index 398bf8630a..846c9caaf3 100644 --- a/lib/vtls/mbedtls.c +++ b/lib/vtls/mbedtls.c @@ -173,8 +173,8 @@ static int mbedtls_bio_cf_read(void *bio, unsigned char *buf, size_t blen) /* See: * https://web.archive.org/web/20200921194007/tls.mbed.org/discussions/generic/howto-determine-exact-buffer-len-for-mbedtls_pk_write_pubkey_der */ -#define RSA_PUB_DER_MAX_BYTES (38 + 2 * MBEDTLS_MPI_MAX_SIZE) -#define ECP_PUB_DER_MAX_BYTES (30 + 2 * MBEDTLS_ECP_MAX_BYTES) +#define RSA_PUB_DER_MAX_BYTES (38 + (2 * MBEDTLS_MPI_MAX_SIZE)) +#define ECP_PUB_DER_MAX_BYTES (30 + (2 * MBEDTLS_ECP_MAX_BYTES)) #define PUB_DER_MAX_BYTES (RSA_PUB_DER_MAX_BYTES > ECP_PUB_DER_MAX_BYTES ? \ RSA_PUB_DER_MAX_BYTES : ECP_PUB_DER_MAX_BYTES) diff --git a/lib/vtls/x509asn1.c b/lib/vtls/x509asn1.c index ff64dc9bf4..e4660801ea 100644 --- a/lib/vtls/x509asn1.c +++ b/lib/vtls/x509asn1.c @@ -983,7 +983,7 @@ static int do_pubkey(struct Curl_easy *data, int certnum, const char *algo, if(!certnum) infof(data, " ECC Public Key (%zu bits)", len); if(data->set.ssl.certinfo) { - char q[sizeof(len) * 8 / 3 + 1]; + char q[(sizeof(len) * 8 / 3) + 1]; (void)curl_msnprintf(q, sizeof(q), "%zu", len); if(ssl_push_certinfo(data, certnum, "ECC Public Key", q)) return 1; @@ -1018,7 +1018,7 @@ static int do_pubkey(struct Curl_easy *data, int certnum, const char *algo, if(!certnum) infof(data, " RSA Public Key (%zu bits)", len); if(data->set.ssl.certinfo) { - char r[sizeof(len) * 8 / 3 + 1]; + char r[(sizeof(len) * 8 / 3) + 1]; curl_msnprintf(r, sizeof(r), "%zu", len); if(ssl_push_certinfo(data, certnum, "RSA Public Key", r)) return 1; diff --git a/src/tool_cb_prg.c b/src/tool_cb_prg.c index 3ac746484f..0280b30849 100644 --- a/src/tool_cb_prg.c +++ b/src/tool_cb_prg.c @@ -78,13 +78,13 @@ static void fly(struct ProgressData *bar, bool moved) memcpy(&buf[bar->bar + 1], "-=O=-", 5); - pos = sinus[bar->tick % 200] / (1000000 / check) + 1; + pos = (sinus[bar->tick % 200] / (1000000 / check)) + 1; buf[pos] = '#'; - pos = sinus[(bar->tick + 5) % 200] / (1000000 / check) + 1; + pos = (sinus[(bar->tick + 5) % 200] / (1000000 / check)) + 1; buf[pos] = '#'; - pos = sinus[(bar->tick + 10) % 200] / (1000000 / check) + 1; + pos = (sinus[(bar->tick + 10) % 200] / (1000000 / check)) + 1; buf[pos] = '#'; - pos = sinus[(bar->tick + 15) % 200] / (1000000 / check) + 1; + pos = (sinus[(bar->tick + 15) % 200] / (1000000 / check)) + 1; buf[pos] = '#'; fputs(buf, bar->out); diff --git a/src/tool_getparam.c b/src/tool_getparam.c index 42c7207242..511a48bf03 100644 --- a/src/tool_getparam.c +++ b/src/tool_getparam.c @@ -618,7 +618,7 @@ UNITTEST ParameterError GetSizeParameter(const char *arg, curl_off_t *out) if(value > ((CURL_OFF_T_MAX - add) / mul)) return PARAM_NUMBER_TOO_LARGE; - *out = value * mul + add; + *out = (value * mul) + add; return PARAM_OK; } diff --git a/src/tool_operate.c b/src/tool_operate.c index 821ab7870b..d97a0c4eb2 100644 --- a/src/tool_operate.c +++ b/src/tool_operate.c @@ -1788,7 +1788,7 @@ static CURLcode check_finished(struct parastate *s) if(retry) { ended->added = FALSE; /* add it again */ /* we delay retries in full integer seconds only */ - ended->startat = delay ? time(NULL) + delay / 1000 : 0; + ended->startat = delay ? time(NULL) + (delay / 1000) : 0; } else { /* result receives this transfer's error unless the transfer was diff --git a/src/tool_paramhlp.c b/src/tool_paramhlp.c index 523b52629c..970d42192a 100644 --- a/src/tool_paramhlp.c +++ b/src/tool_paramhlp.c @@ -326,7 +326,7 @@ ParameterError secs2ms(long *valp, const char *str) ms = ((long)fracs * 100) / digs[len - 1]; } - *valp = (long)secs * 1000 + ms; + *valp = ((long)secs * 1000) + ms; return PARAM_OK; } diff --git a/src/tool_setopt.c b/src/tool_setopt.c index 750ef169d3..bd24e4b411 100644 --- a/src/tool_setopt.c +++ b/src/tool_setopt.c @@ -184,7 +184,7 @@ static char *c_escape(const char *str, curl_off_t len) CURLcode result; struct dynbuf escaped; - curlx_dyn_init(&escaped, 4 * MAX_STRING_LENGTH_OUTPUT + 3); + curlx_dyn_init(&escaped, (4 * MAX_STRING_LENGTH_OUTPUT) + 3); if(len == ZERO_TERMINATED) len = strlen(str); @@ -211,7 +211,7 @@ static char *c_escape(const char *str, curl_off_t len) if(!result) { if(p && *p) - result = curlx_dyn_addn(&escaped, to + 2 * (p - from), 2); + result = curlx_dyn_addn(&escaped, to + (2 * (p - from)), 2); else { result = curlx_dyn_addf(&escaped, /* Octal escape to avoid >2 digit hex. */ diff --git a/src/tool_urlglob.c b/src/tool_urlglob.c index 4c5973875b..b8144c8673 100644 --- a/src/tool_urlglob.c +++ b/src/tool_urlglob.c @@ -272,8 +272,8 @@ static CURLcode glob_range(struct URLGlob *glob, const char **patternp, pat->c.ascii.letter = pat->c.ascii.min = min_c; pat->c.ascii.max = max_c; - if(multiply(amount, ((pat->c.ascii.max - pat->c.ascii.min) / - pat->c.ascii.step + 1))) + if(multiply(amount, (((pat->c.ascii.max - pat->c.ascii.min) / + pat->c.ascii.step) + 1))) return globerror(glob, "range overflow", *posp, CURLE_URL_MALFORMAT); } else if(ISDIGIT(*pattern)) { @@ -328,8 +328,8 @@ static CURLcode glob_range(struct URLGlob *glob, const char **patternp, pat->c.num.max = max_n; pat->c.num.step = step_n; - if(multiply(amount, ((pat->c.num.max - pat->c.num.min) / - pat->c.num.step + 1))) + if(multiply(amount, (((pat->c.num.max - pat->c.num.min) / + pat->c.num.step) + 1))) return globerror(glob, "range overflow", *posp, CURLE_URL_MALFORMAT); } else diff --git a/tests/libtest/first.c b/tests/libtest/first.c index eff83aefab..16be8ef9e6 100644 --- a/tests/libtest/first.c +++ b/tests/libtest/first.c @@ -147,7 +147,7 @@ static void memory_tracking_init(void) /* returns a hexdump in a static memory area */ char *hexdump(const unsigned char *buf, size_t len) { - static char dump[200 * 3 + 1]; + static char dump[(200 * 3) + 1]; char *p = dump; size_t i; if(len > 200) diff --git a/tests/libtest/lib530.c b/tests/libtest/lib530.c index cbc5130c79..ad2ad536f7 100644 --- a/tests/libtest/lib530.c +++ b/tests/libtest/lib530.c @@ -217,7 +217,7 @@ static ssize_t t530_getMicroSecondTimeout(struct curltime *timeout) struct curltime now; ssize_t result; now = curlx_now(); - result = (ssize_t)((timeout->tv_sec - now.tv_sec) * 1000000 + + result = (ssize_t)(((timeout->tv_sec - now.tv_sec) * 1000000) + timeout->tv_usec - now.tv_usec); if(result < 0) result = 0; diff --git a/tests/libtest/lib582.c b/tests/libtest/lib582.c index 7b640a0b7b..3a4e278e38 100644 --- a/tests/libtest/lib582.c +++ b/tests/libtest/lib582.c @@ -164,7 +164,7 @@ static ssize_t t582_getMicroSecondTimeout(struct curltime *timeout) struct curltime now; ssize_t result; now = curlx_now(); - result = (ssize_t)((timeout->tv_sec - now.tv_sec) * 1000000 + + result = (ssize_t)(((timeout->tv_sec - now.tv_sec) * 1000000) + timeout->tv_usec - now.tv_usec); if(result < 0) result = 0; diff --git a/tests/libtest/lib597.c b/tests/libtest/lib597.c index 476da71f16..0c1fc473f1 100644 --- a/tests/libtest/lib597.c +++ b/tests/libtest/lib597.c @@ -98,7 +98,7 @@ static CURLcode test_lib597(const char *URL) interval.tv_usec = (itimeout % 1000) * 1000; } else { - interval.tv_sec = TEST_HANG_TIMEOUT / 1000 - 1; + interval.tv_sec = (TEST_HANG_TIMEOUT / 1000) - 1; interval.tv_usec = 0; } diff --git a/tests/libtest/lib666.c b/tests/libtest/lib666.c index 5a5d644cec..55dd33ab35 100644 --- a/tests/libtest/lib666.c +++ b/tests/libtest/lib666.c @@ -40,7 +40,7 @@ static CURLcode test_lib666(const char *URL) if(i % 77 == 76) testbuf[i] = '\n'; else - testbuf[i] = (char)(0x41 + i % 26); /* A...Z */ + testbuf[i] = (char)(0x41 + (i % 26)); /* A...Z */ if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { curl_mfprintf(stderr, "curl_global_init() failed\n"); diff --git a/tests/libtest/lib758.c b/tests/libtest/lib758.c index 71d75b1028..e743da7f58 100644 --- a/tests/libtest/lib758.c +++ b/tests/libtest/lib758.c @@ -263,7 +263,7 @@ static ssize_t t758_getMicroSecondTimeout(struct curltime *timeout) struct curltime now; ssize_t result; now = curlx_now(); - result = (ssize_t)((timeout->tv_sec - now.tv_sec) * 1000000 + + result = (ssize_t)(((timeout->tv_sec - now.tv_sec) * 1000000) + timeout->tv_usec - now.tv_usec); if(result < 0) result = 0; diff --git a/tests/server/rtspd.c b/tests/server/rtspd.c index 80eb22abf2..fcc97b2ca3 100644 --- a/tests/server/rtspd.c +++ b/tests/server/rtspd.c @@ -180,7 +180,7 @@ static int rtspd_ProcessRequest(struct rtspd_httprequest *req) return 1; } - req->prot_version = prot_major * 10 + prot_minor; + req->prot_version = (prot_major * 10) + prot_minor; /* find the last slash */ ptr = strrchr(doc, '/'); diff --git a/tests/server/socksd.c b/tests/server/socksd.c index 85001340c2..f9bff8d5f3 100644 --- a/tests/server/socksd.c +++ b/tests/server/socksd.c @@ -293,8 +293,8 @@ static curl_socket_t socks4(curl_socket_t fd, static curl_socket_t sockit(curl_socket_t fd) { - unsigned char buffer[2 * 256 + 16]; - unsigned char response[2 * 256 + 16]; + unsigned char buffer[(2 * 256) + 16]; + unsigned char response[(2 * 256) + 16]; ssize_t rc; unsigned char len; unsigned char type; diff --git a/tests/server/sws.c b/tests/server/sws.c index c1b246d50f..e0072506fd 100644 --- a/tests/server/sws.c +++ b/tests/server/sws.c @@ -386,7 +386,7 @@ static int sws_ProcessRequest(struct sws_httprequest *req) if(fine) { const char *ptr; - req->prot_version = prot_major * 10 + prot_minor; + req->prot_version = (prot_major * 10) + prot_minor; /* find the last slash */ ptr = &httppath[npath]; diff --git a/tests/unit/unit1309.c b/tests/unit/unit1309.c index b5620dcdbb..5807d497ee 100644 --- a/tests/unit/unit1309.c +++ b/tests/unit/unit1309.c @@ -109,9 +109,9 @@ static CURLcode test_unit1309(const char *arg) /* add some nodes with the same key */ for(j = 0; j <= i % 3; j++) { - storage[i * 3 + j] = key.tv_usec * 10 + j; - Curl_splayset(&nodes[i * 3 + j], &storage[i * 3 + j]); - root = Curl_splayinsert(&key, root, &nodes[i * 3 + j]); + storage[(i * 3) + j] = (key.tv_usec * 10) + j; + Curl_splayset(&nodes[(i * 3) + j], &storage[(i * 3) + j]); + root = Curl_splayinsert(&key, root, &nodes[(i * 3) + j]); } }