From: Viktor Szakats Date: Tue, 8 Jul 2025 12:10:35 +0000 (+0200) Subject: tidy-up: move literal to the right side of comparisons X-Git-Tag: curl-8_16_0~378 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b2bccdc257d0bab662778a8e5f8391dc99a8830b;p=thirdparty%2Fcurl.git tidy-up: move literal to the right side of comparisons Closes #17876 --- diff --git a/docs/examples/anyauthput.c b/docs/examples/anyauthput.c index 550c827693..7106c32eb6 100644 --- a/docs/examples/anyauthput.c +++ b/docs/examples/anyauthput.c @@ -61,7 +61,7 @@ static int my_seek(void *userp, curl_off_t offset, int origin) { FILE *fp = (FILE *) userp; - if(-1 == fseek(fp, (long) offset, origin)) + if(fseek(fp, (long) offset, origin) == -1) /* could not seek */ return CURL_SEEKFUNC_CANTSEEK; diff --git a/docs/examples/block_ip.c b/docs/examples/block_ip.c index bff7b6353c..a6609d3428 100644 --- a/docs/examples/block_ip.c +++ b/docs/examples/block_ip.c @@ -155,7 +155,7 @@ static struct ip *ip_list_append(struct ip *list, const char *data) ip->maskbits = 128; #endif - if(1 != inet_pton(ip->family, ip->str, &ip->netaddr)) { + if(inet_pton(ip->family, ip->str, &ip->netaddr) != 1) { free(ip->str); free(ip); return NULL; diff --git a/docs/examples/multithread.c b/docs/examples/multithread.c index 7978419bdc..ceee94022a 100644 --- a/docs/examples/multithread.c +++ b/docs/examples/multithread.c @@ -80,7 +80,7 @@ int main(void) NULL, /* default attributes please */ pull_one_url, (void *)urls[i]); - if(0 != error) + if(error) fprintf(stderr, "Couldn't run thread number %d, errno %d\n", i, error); else fprintf(stderr, "Thread %d, gets %s\n", i, urls[i]); diff --git a/docs/examples/sftpuploadresume.c b/docs/examples/sftpuploadresume.c index 2803da33e0..f1f7b0c275 100644 --- a/docs/examples/sftpuploadresume.c +++ b/docs/examples/sftpuploadresume.c @@ -83,7 +83,7 @@ static int sftpResumeUpload(CURL *curlhandle, const char *remotepath, CURLcode result = CURLE_GOT_NOTHING; curl_off_t remoteFileSizeByte = sftpGetRemoteFileSize(remotepath); - if(-1 == remoteFileSizeByte) { + if(remoteFileSizeByte == -1) { printf("Error reading the remote file size: unable to resume upload\n"); return -1; } diff --git a/docs/examples/smooth-gtk-thread.c b/docs/examples/smooth-gtk-thread.c index c53951262a..49a412d958 100644 --- a/docs/examples/smooth-gtk-thread.c +++ b/docs/examples/smooth-gtk-thread.c @@ -130,7 +130,7 @@ void *create_thread(void *progress_bar) NULL, /* default attributes please */ pull_one_url, NULL); - if(0 != error) + if(error) fprintf(stderr, "Couldn't run thread number %d, errno %d\n", i, error); else fprintf(stderr, "Thread %d, gets %s\n", i, urls[i]); diff --git a/docs/examples/threaded-ssl.c b/docs/examples/threaded-ssl.c index 263400afd8..9668129055 100644 --- a/docs/examples/threaded-ssl.c +++ b/docs/examples/threaded-ssl.c @@ -83,7 +83,7 @@ int main(int argc, char **argv) NULL, /* default attributes please */ pull_one_url, (void *)urls[i]); - if(0 != error) + if(error) fprintf(stderr, "Couldn't run thread number %d, errno %d\n", i, error); else fprintf(stderr, "Thread %d, gets %s\n", i, urls[i]); diff --git a/docs/internals/CODE_STYLE.md b/docs/internals/CODE_STYLE.md index 24e669c35b..dadec934dd 100644 --- a/docs/internals/CODE_STYLE.md +++ b/docs/internals/CODE_STYLE.md @@ -253,7 +253,7 @@ If no parenthesis, use the default indent: ```c data->set.http_disable_hostname_check_before_authentication = - (0 != va_arg(param, long)) ? TRUE : FALSE; + va_arg(param, long) ? TRUE : FALSE; ``` Function invoke with an open parenthesis: diff --git a/lib/altsvc.c b/lib/altsvc.c index 59476d7325..a06f40bc2a 100644 --- a/lib/altsvc.c +++ b/lib/altsvc.c @@ -260,11 +260,11 @@ static CURLcode altsvc_out(struct altsvc *as, FILE *fp) #ifdef USE_IPV6 else { char ipv6_unused[16]; - if(1 == curlx_inet_pton(AF_INET6, as->dst.host, ipv6_unused)) { + if(curlx_inet_pton(AF_INET6, as->dst.host, ipv6_unused) == 1) { dst6_pre = "["; dst6_post = "]"; } - if(1 == curlx_inet_pton(AF_INET6, as->src.host, ipv6_unused)) { + if(curlx_inet_pton(AF_INET6, as->src.host, ipv6_unused) == 1) { src6_pre = "["; src6_post = "]"; } diff --git a/lib/cf-socket.c b/lib/cf-socket.c index 3d535a0e10..49bc611fb9 100644 --- a/lib/cf-socket.c +++ b/lib/cf-socket.c @@ -844,7 +844,7 @@ static bool verifyconnect(curl_socket_t sockfd, int *error) #endif - if(0 != getsockopt(sockfd, SOL_SOCKET, SO_ERROR, (void *)&err, &errSize)) + if(getsockopt(sockfd, SOL_SOCKET, SO_ERROR, (void *)&err, &errSize)) err = SOCKERRNO; #ifdef UNDER_CE /* Old Windows CE versions do not support SO_ERROR */ @@ -860,7 +860,7 @@ static bool verifyconnect(curl_socket_t sockfd, int *error) err = 0; } #endif - if((0 == err) || (SOCKEISCONN == err)) + if((err == 0) || (SOCKEISCONN == err)) /* we are connected, awesome! */ rc = TRUE; else @@ -2111,7 +2111,7 @@ static CURLcode cf_tcp_accept_connect(struct Curl_cfilter *cf, return CURLE_OK; } - if(0 == getsockname(ctx->sock, (struct sockaddr *) &add, &size)) { + if(!getsockname(ctx->sock, (struct sockaddr *) &add, &size)) { size = sizeof(add); #ifdef HAVE_ACCEPT4 s_accepted = accept4(ctx->sock, (struct sockaddr *) &add, &size, diff --git a/lib/conncache.c b/lib/conncache.c index fd6776e34c..f77a746874 100644 --- a/lib/conncache.c +++ b/lib/conncache.c @@ -515,7 +515,7 @@ static bool cpool_foreach(struct Curl_easy *data, struct connectdata *conn = Curl_node_elem(curr); curr = Curl_node_next(curr); - if(1 == func(data, conn, param)) { + if(func(data, conn, param) == 1) { return TRUE; } } diff --git a/lib/cookie.c b/lib/cookie.c index 9221871e4b..914a4aca12 100644 --- a/lib/cookie.c +++ b/lib/cookie.c @@ -167,13 +167,13 @@ static bool pathmatch(const char *cookie_path, const char *uri_path) /* cookie_path must not have last '/' separator. ex: /sample */ cookie_path_len = strlen(cookie_path); - if(1 == cookie_path_len) { + if(cookie_path_len == 1) { /* cookie_path must be '/' */ return TRUE; } /* #-fragments are already cut off! */ - if(0 == strlen(uri_path) || uri_path[0] != '/') + if(strlen(uri_path) == 0 || uri_path[0] != '/') uri_path = "/"; /* @@ -872,7 +872,7 @@ parse_netscape(struct Cookie *co, break; } } - if(6 == fields) { + if(fields == 6) { /* we got a cookie with blank contents, fix it */ co->value = strdup(""); if(!co->value) @@ -881,7 +881,7 @@ parse_netscape(struct Cookie *co, fields++; } - if(7 != fields) + if(fields != 7) /* we did not find the sufficient number of fields */ return CERR_FIELDS; diff --git a/lib/curl_addrinfo.c b/lib/curl_addrinfo.c index 310a5b6ab8..61db84ab19 100644 --- a/lib/curl_addrinfo.c +++ b/lib/curl_addrinfo.c @@ -544,7 +544,7 @@ curl_dbg_getaddrinfo(const char *hostname, #else int res = getaddrinfo(hostname, service, hints, result); #endif - if(0 == res) + if(res == 0) /* success */ curl_dbg_log("ADDR %s:%d getaddrinfo() = %p\n", source, line, (void *)*result); diff --git a/lib/curl_sha512_256.c b/lib/curl_sha512_256.c index d730c59a1b..fad43d2a33 100644 --- a/lib/curl_sha512_256.c +++ b/lib/curl_sha512_256.c @@ -317,7 +317,7 @@ static CURL_FORCEINLINE curl_uint64_t Curl_rotr64(curl_uint64_t value, unsigned int bits) { bits %= 64; - if(0 == bits) + if(bits == 0) return value; /* Defined in a form which modern compiler could optimize. */ return (value >> bits) | (value << (64 - bits)); @@ -621,7 +621,7 @@ static CURLcode Curl_sha512_256_update(void *context, DEBUGASSERT((data != NULL) || (length == 0)); - if(0 == length) + if(length == 0) return CURLE_OK; /* Shortcut, do nothing */ /* Note: (count & (CURL_SHA512_256_BLOCK_SIZE-1)) @@ -633,7 +633,7 @@ static CURLcode Curl_sha512_256_update(void *context, ctx->count_bits_hi += ctx->count >> 61; ctx->count &= CURL_UINT64_C(0x1FFFFFFFFFFFFFFF); - if(0 != bytes_have) { + if(bytes_have) { unsigned int bytes_left = CURL_SHA512_256_BLOCK_SIZE - bytes_have; if(length >= bytes_left) { /* Combine new data with data in the buffer and process the full @@ -656,7 +656,7 @@ static CURLcode Curl_sha512_256_update(void *context, length -= CURL_SHA512_256_BLOCK_SIZE; } - if(0 != length) { + if(length) { /* Copy incomplete block of new data (if any) to the buffer. */ memcpy(((unsigned char *) ctx_buf) + bytes_have, data, length); diff --git a/lib/curlx/timeval.c b/lib/curlx/timeval.c index 01393bd528..bd8b9bcee2 100644 --- a/lib/curlx/timeval.c +++ b/lib/curlx/timeval.c @@ -115,7 +115,7 @@ struct curltime curlx_now(void) (HAVE_BUILTIN_AVAILABLE == 1) have_clock_gettime && #endif - (0 == clock_gettime(CLOCK_MONOTONIC_RAW, &tsnow))) { + (clock_gettime(CLOCK_MONOTONIC_RAW, &tsnow) == 0)) { cnow.tv_sec = tsnow.tv_sec; cnow.tv_usec = (int)(tsnow.tv_nsec / 1000); } @@ -127,7 +127,7 @@ struct curltime curlx_now(void) (HAVE_BUILTIN_AVAILABLE == 1) have_clock_gettime && #endif - (0 == clock_gettime(CLOCK_MONOTONIC, &tsnow))) { + (clock_gettime(CLOCK_MONOTONIC, &tsnow) == 0)) { cnow.tv_sec = tsnow.tv_sec; cnow.tv_usec = (int)(tsnow.tv_nsec / 1000); } @@ -168,7 +168,7 @@ struct curltime curlx_now(void) struct curltime cnow; uint64_t usecs; - if(0 == timebase.denom) + if(timebase.denom == 0) (void)mach_timebase_info(&timebase); usecs = mach_absolute_time(); diff --git a/lib/file.c b/lib/file.c index b88f612305..297503edcc 100644 --- a/lib/file.c +++ b/lib/file.c @@ -358,7 +358,7 @@ static CURLcode file_upload(struct Curl_easy *data, return CURLE_WRITE_ERROR; } - if(-1 != data->state.infilesize) + if(data->state.infilesize != -1) /* known size of data to "upload" */ Curl_pgrsSetUploadSize(data, data->state.infilesize); @@ -470,7 +470,7 @@ static CURLcode file_do(struct Curl_easy *data, bool *done) fd = file->fd; /* VMS: This only works reliable for STREAMLF files */ - if(-1 != fstat(fd, &statbuf)) { + if(fstat(fd, &statbuf) != -1) { if(!S_ISDIR(statbuf.st_mode)) expected_size = statbuf.st_size; /* and store the modification time */ diff --git a/lib/ftp.c b/lib/ftp.c index f763b183b1..a82cb473ef 100644 --- a/lib/ftp.c +++ b/lib/ftp.c @@ -615,7 +615,7 @@ static CURLcode ftp_readresp(struct Curl_easy *data, if(ftpcode) *ftpcode = code; - if(421 == code) { + if(code == 421) { /* 421 means "Service not available, closing control connection." and FTP * servers use it to signal that idle session timeout has been exceeded. * If we ignored the response, it could end up hanging in some cases. @@ -2356,7 +2356,7 @@ static CURLcode ftp_state_size_resp(struct Curl_easy *data, if(instate == FTP_SIZE) { #ifdef CURL_FTP_HTTPSTYLE_HEAD - if(-1 != filesize) { + if(filesize != -1) { char clbuf[128]; int clbuflen = msnprintf(clbuf, sizeof(clbuf), "Content-Length: %" FMT_OFF_T "\r\n", filesize); @@ -3439,7 +3439,7 @@ static CURLcode ftp_done(struct Curl_easy *data, CURLcode status, } } else { - if((-1 != data->req.size) && + if((data->req.size != -1) && (data->req.size != data->req.bytecount) && (data->req.maxdownload != data->req.bytecount)) { failf(data, "Received only partial file: %" FMT_OFF_T " bytes", diff --git a/lib/hostip6.c b/lib/hostip6.c index ce7f5050ea..fa2ff33b2c 100644 --- a/lib/hostip6.c +++ b/lib/hostip6.c @@ -114,8 +114,8 @@ struct Curl_addrinfo *Curl_sync_getaddrinfo(struct Curl_easy *data, * The AI_NUMERICHOST must not be set to get synthesized IPv6 address from * an IPv4 address on iOS and macOS. */ - if((1 == curlx_inet_pton(AF_INET, hostname, addrbuf)) || - (1 == curlx_inet_pton(AF_INET6, hostname, addrbuf))) { + if((curlx_inet_pton(AF_INET, hostname, addrbuf) == 1) || + (curlx_inet_pton(AF_INET6, hostname, addrbuf) == 1)) { /* the given address is numerical only, prevent a reverse lookup */ hints.ai_flags = AI_NUMERICHOST; } diff --git a/lib/http.c b/lib/http.c index 71a4857249..78c9a2dccb 100644 --- a/lib/http.c +++ b/lib/http.c @@ -3949,7 +3949,7 @@ static CURLcode http_on_response(struct Curl_easy *data, like to call http2_handle_stream_close to properly close a stream. In order to do this, we keep reading until we close the stream. */ - if((0 == k->maxdownload) && (k->httpversion_sent < 20)) + if((k->maxdownload == 0) && (k->httpversion_sent < 20)) k->download_done = TRUE; /* final response without error, prepare to receive the body */ diff --git a/lib/http_chunks.c b/lib/http_chunks.c index 63e477c48a..f014a256ab 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -159,7 +159,7 @@ static CURLcode httpchunk_readwrite(struct Curl_easy *data, } else { const char *p; - if(0 == ch->hexindex) { + if(ch->hexindex == 0) { /* This is illegal data, we received junk where we expected a hexadecimal digit. */ failf(data, "chunk hex-length char not a hex digit: 0x%x", *buf); @@ -184,7 +184,7 @@ static CURLcode httpchunk_readwrite(struct Curl_easy *data, /* waiting for the LF after a chunk size */ if(*buf == 0x0a) { /* we are now expecting data to come, unless size was zero! */ - if(0 == ch->datasize) { + if(ch->datasize == 0) { ch->state = CHUNK_TRAILER; /* now check for trailers */ } else { @@ -229,7 +229,7 @@ static CURLcode httpchunk_readwrite(struct Curl_easy *data, FMT_OFF_T " bytes in chunk remain", piece, ch->datasize); - if(0 == ch->datasize) + if(ch->datasize == 0) /* end of data this round, we now expect a trailing CRLF */ ch->state = CHUNK_POSTLF; break; diff --git a/lib/memdebug.c b/lib/memdebug.c index bdcdcbb907..d063f94c32 100644 --- a/lib/memdebug.c +++ b/lib/memdebug.c @@ -356,7 +356,7 @@ int curl_dbg_socketpair(int domain, int type, int protocol, { int res = (socketpair)(domain, type, protocol, socket_vector); - if(source && (0 == res)) + if(source && (res == 0)) curl_dbg_log("FD %s:%d socketpair() = " "%" FMT_SOCKET_T " %" FMT_SOCKET_T "\n", source, line, socket_vector[0], socket_vector[1]); diff --git a/lib/noproxy.c b/lib/noproxy.c index 306cd6d1f9..22b067ad1b 100644 --- a/lib/noproxy.c +++ b/lib/noproxy.c @@ -54,9 +54,9 @@ UNITTEST bool Curl_cidr4_match(const char *ipv4, /* 1.2.3.4 address */ /* strange input */ return FALSE; - if(1 != curlx_inet_pton(AF_INET, ipv4, &address)) + if(curlx_inet_pton(AF_INET, ipv4, &address) != 1) return FALSE; - if(1 != curlx_inet_pton(AF_INET, network, &check)) + if(curlx_inet_pton(AF_INET, network, &check) != 1) return FALSE; if(bits && (bits != 32)) { @@ -92,9 +92,9 @@ UNITTEST bool Curl_cidr6_match(const char *ipv6, rest = bits & 0x07; if((bytes > 16) || ((bytes == 16) && rest)) return FALSE; - if(1 != curlx_inet_pton(AF_INET6, ipv6, address)) + if(curlx_inet_pton(AF_INET6, ipv6, address) != 1) return FALSE; - if(1 != curlx_inet_pton(AF_INET6, network, check)) + if(curlx_inet_pton(AF_INET6, network, check) != 1) return FALSE; if(bytes && memcmp(address, check, bytes)) return FALSE; @@ -163,7 +163,7 @@ bool Curl_check_noproxy(const char *name, const char *no_proxy) else { unsigned int address; namelen = strlen(name); - if(1 == curlx_inet_pton(AF_INET, name, &address)) + if(curlx_inet_pton(AF_INET, name, &address) == 1) type = TYPE_IPV4; else { /* ignore trailing dots in the hostname */ diff --git a/lib/progress.c b/lib/progress.c index 746805f20f..1a3f4334ca 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -449,7 +449,7 @@ static bool progress_calc(struct Curl_easy *data, struct curltime now) /* Figure out the exact time for the time span */ span_ms = curlx_timediff(now, p->speeder_time[checkindex]); - if(0 == span_ms) + if(span_ms == 0) span_ms = 1; /* at least one millisecond MUST have passed */ /* Calculate the average speed the last 'span_ms' milliseconds */ diff --git a/lib/sendf.c b/lib/sendf.c index 9b6908f92d..6bd4b1bfba 100644 --- a/lib/sendf.c +++ b/lib/sendf.c @@ -281,7 +281,7 @@ static CURLcode cw_download_write(struct Curl_easy *data, * This gives deterministic BODY writes on varying buffer receive * lengths. */ nwrite = nbytes; - if(-1 != data->req.maxdownload) { + if(data->req.maxdownload != -1) { size_t wmax = get_max_body_write_len(data, data->req.maxdownload); if(nwrite > wmax) { excess_len = nbytes - wmax; @@ -879,7 +879,7 @@ static CURLcode cr_in_rewind(struct Curl_easy *data, int err = fseek(data->state.in, 0, SEEK_SET); CURL_TRC_READ(data, "cr_in, rewind via fseek -> %d(%d)", (int)err, (int)errno); - if(-1 != err) + if(err != -1) /* successful rewind */ return CURLE_OK; } diff --git a/lib/setopt.c b/lib/setopt.c index 1be45dc05b..ca03fa371c 100644 --- a/lib/setopt.c +++ b/lib/setopt.c @@ -443,7 +443,7 @@ static void set_ssl_options(struct ssl_config_data *ssl, static CURLcode setopt_long(struct Curl_easy *data, CURLoption option, long arg) { - bool enabled = (0 != arg); + bool enabled = !!arg; unsigned long uarg = (unsigned long)arg; switch(option) { case CURLOPT_DNS_CACHE_TIMEOUT: diff --git a/lib/socks.c b/lib/socks.c index 58132cb42d..46daf53baa 100644 --- a/lib/socks.c +++ b/lib/socks.c @@ -876,7 +876,7 @@ CONNECT_RESOLVE_REMOTE: #ifdef USE_IPV6 if(conn->bits.ipv6_ip) { char ip6[16]; - if(1 != curlx_inet_pton(AF_INET6, sx->hostname, ip6)) + if(curlx_inet_pton(AF_INET6, sx->hostname, ip6) != 1) return CURLPX_BAD_ADDRESS_TYPE; socksreq[len++] = 4; memcpy(&socksreq[len], ip6, sizeof(ip6)); @@ -884,7 +884,7 @@ CONNECT_RESOLVE_REMOTE: } else #endif - if(1 == curlx_inet_pton(AF_INET, sx->hostname, ip4)) { + if(curlx_inet_pton(AF_INET, sx->hostname, ip4) == 1) { socksreq[len++] = 1; memcpy(&socksreq[len], ip4, sizeof(ip4)); len += sizeof(ip4); diff --git a/lib/socks_gssapi.c b/lib/socks_gssapi.c index f23a1ae6ed..0a7ddd5ff1 100644 --- a/lib/socks_gssapi.c +++ b/lib/socks_gssapi.c @@ -212,7 +212,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, code = Curl_conn_cf_send(cf->next, data, (char *)socksreq, 4, FALSE, &nwritten); - if(code || (4 != nwritten)) { + if(code || (nwritten != 4)) { failf(data, "Failed to send GSS-API authentication request."); gss_release_name(&gss_status, &server); gss_release_buffer(&gss_status, &gss_recv_token); @@ -420,7 +420,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, code = Curl_conn_cf_send(cf->next, data, (char *)socksreq, 4, FALSE, &nwritten); - if(code || (4 != nwritten)) { + if(code || (nwritten != 4)) { failf(data, "Failed to send GSS-API encryption request."); gss_release_buffer(&gss_status, &gss_w_token); Curl_gss_delete_sec_context(&gss_status, &gss_context, NULL); @@ -431,7 +431,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, memcpy(socksreq, &gss_enc, 1); code = Curl_conn_cf_send(cf->next, data, (char *)socksreq, 1, FALSE, &nwritten); - if(code || (1 != nwritten)) { + if(code || (nwritten != 1)) { failf(data, "Failed to send GSS-API encryption type."); Curl_gss_delete_sec_context(&gss_status, &gss_context, NULL); return CURLE_COULDNT_CONNECT; diff --git a/lib/socks_sspi.c b/lib/socks_sspi.c index 82147562b7..1e80ee18d9 100644 --- a/lib/socks_sspi.c +++ b/lib/socks_sspi.c @@ -209,7 +209,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, code = Curl_conn_cf_send(cf->next, data, (char *)socksreq, 4, FALSE, &written); - if(code || (4 != written)) { + if(code || (written != 4)) { failf(data, "Failed to send SSPI authentication request."); free(service_name); if(sspi_send_token.pvBuffer) @@ -480,7 +480,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, code = Curl_conn_cf_send(cf->next, data, (char *)socksreq, 4, FALSE, &written); - if(code || (4 != written)) { + if(code || (written != 4)) { failf(data, "Failed to send SSPI encryption request."); if(sspi_send_token.pvBuffer) Curl_pSecFn->FreeContextBuffer(sspi_send_token.pvBuffer); @@ -492,7 +492,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, memcpy(socksreq, &gss_enc, 1); code = Curl_conn_cf_send(cf->next, data, (char *)socksreq, 1, FALSE, &written); - if(code || (1 != written)) { + if(code || (written != 1)) { failf(data, "Failed to send SSPI encryption type."); Curl_pSecFn->DeleteSecurityContext(&sspi_context); return CURLE_COULDNT_CONNECT; diff --git a/lib/strequal.c b/lib/strequal.c index fb6be51dd5..17dd34b7f3 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -59,7 +59,7 @@ static int ncasecompare(const char *first, const char *second, size_t max) first++; second++; } - if(0 == max) + if(max == 0) return 1; /* they are equal this far */ return Curl_raw_toupper(*first) == Curl_raw_toupper(*second); diff --git a/lib/strerror.c b/lib/strerror.c index 90694882c3..f0f36ed1b7 100644 --- a/lib/strerror.c +++ b/lib/strerror.c @@ -809,7 +809,7 @@ const char *Curl_strerror(int err, char *buf, size_t buflen) * storage is supplied via 'strerrbuf' and 'buflen' to hold the generated * message string, or EINVAL if 'errnum' is not a valid error number. */ - if(0 != strerror_r(err, buf, buflen)) { + if(strerror_r(err, buf, buflen)) { if('\0' == buf[0]) curl_msnprintf(buf, buflen, "Unknown error %d", err); } diff --git a/lib/transfer.c b/lib/transfer.c index 15a61f6997..84e4c5e927 100644 --- a/lib/transfer.c +++ b/lib/transfer.c @@ -481,7 +481,7 @@ CURLcode Curl_sendrecv(struct Curl_easy *data, struct curltime *nowp) } /* If there is nothing more to send/recv, the request is done */ - if(0 == (k->keepon&(KEEP_RECVBITS|KEEP_SENDBITS))) + if((k->keepon & (KEEP_RECVBITS|KEEP_SENDBITS)) == 0) data->req.done = TRUE; out: diff --git a/lib/urlapi.c b/lib/urlapi.c index c266fd3ebc..2ed1a9b0d6 100644 --- a/lib/urlapi.c +++ b/lib/urlapi.c @@ -511,7 +511,7 @@ static CURLUcode ipv6_parse(struct Curl_URL *u, char *hostname, { char dest[16]; /* fits a binary IPv6 address */ hostname[hlen] = 0; /* end the address there */ - if(1 != curlx_inet_pton(AF_INET6, hostname, dest)) + if(curlx_inet_pton(AF_INET6, hostname, dest) != 1) return CURLUE_BAD_IPV6; if(curlx_inet_ntop(AF_INET6, dest, hostname, hlen)) { hlen = strlen(hostname); /* might be shorter now */ diff --git a/lib/vtls/gtls.c b/lib/vtls/gtls.c index 405c8e7ff3..052e18de6c 100644 --- a/lib/vtls/gtls.c +++ b/lib/vtls/gtls.c @@ -1967,7 +1967,7 @@ static bool gtls_data_pending(struct Curl_cfilter *cf, DEBUGASSERT(ctx && ctx->backend); backend = (struct gtls_ssl_backend_data *)ctx->backend; if(backend->gtls.session && - 0 != gnutls_record_check_pending(backend->gtls.session)) + gnutls_record_check_pending(backend->gtls.session) != 0) return TRUE; return FALSE; } diff --git a/lib/vtls/openssl.c b/lib/vtls/openssl.c index 76c4968d8b..1385f3cf19 100644 --- a/lib/vtls/openssl.c +++ b/lib/vtls/openssl.c @@ -958,7 +958,7 @@ static char *ossl_strerror(unsigned long error, char *buf, size_t size) static int passwd_callback(char *buf, int num, int encrypting, void *password) { - DEBUGASSERT(0 == encrypting); + DEBUGASSERT(encrypting == 0); if(!encrypting && num >= 0 && password) { int klen = curlx_uztosi(strlen((char *)password)); @@ -975,7 +975,7 @@ static int passwd_callback(char *buf, int num, int encrypting, */ static bool rand_enough(void) { - return 0 != RAND_status(); + return RAND_status() != 0; } static CURLcode ossl_seed(struct Curl_easy *data) @@ -4487,7 +4487,7 @@ static CURLcode ossl_connect_step2(struct Curl_cfilter *cf, /* 1 is fine 0 is "not successful but was shut down controlled" <0 is "handshake was not successful, because a fatal error occurred" */ - if(1 != err) { + if(err != 1) { int detail = SSL_get_error(octx->ssl, err); CURL_TRC_CF(data, cf, "SSL_connect() -> err=%d, detail=%d", err, detail); diff --git a/lib/vtls/schannel.c b/lib/vtls/schannel.c index 8d16d70392..fe997ee200 100644 --- a/lib/vtls/schannel.c +++ b/lib/vtls/schannel.c @@ -379,7 +379,7 @@ set_ssl_ciphers(SCHANNEL_CRED *schannel_cred, char *ciphers, { const char *startCur = ciphers; int algCount = 0; - while(startCur && (0 != *startCur) && (algCount < NUM_CIPHERS)) { + while(startCur && *startCur && (algCount < NUM_CIPHERS)) { curl_off_t alg; if(curlx_str_number(&startCur, &alg, INT_MAX) || !alg) alg = get_alg_id_by_name(startCur); @@ -1816,7 +1816,7 @@ schannel_send(struct Curl_cfilter *cf, struct Curl_easy *data, result = CURLE_SEND_ERROR; break; } - else if(0 == what) { + else if(what == 0) { failf(data, "schannel: timed out sending data " "(bytes sent: %zu)", *pnwritten); result = CURLE_OPERATION_TIMEDOUT; diff --git a/lib/vtls/vtls.c b/lib/vtls/vtls.c index 942224feff..e4d20e2123 100644 --- a/lib/vtls/vtls.c +++ b/lib/vtls/vtls.c @@ -670,7 +670,7 @@ static CURLcode pubkey_pem_to_der(const char *pem, pem_count = begin_pos - pem; /* Invalid if not at beginning AND not directly following \n */ - if(0 != pem_count && '\n' != pem[pem_count - 1]) + if(pem_count && '\n' != pem[pem_count - 1]) return CURLE_BAD_CONTENT_ENCODING; /* 26 is length of "-----BEGIN PUBLIC KEY-----" */ @@ -1790,7 +1790,7 @@ static CURLcode vtls_shutdown_blocking(struct Curl_cfilter *cf, result = CURLE_RECV_ERROR; goto out; } - else if(0 == what) { + else if(what == 0) { /* timeout */ failf(data, "SSL shutdown timeout"); result = CURLE_OPERATION_TIMEDOUT; diff --git a/lib/vtls/wolfssl.c b/lib/vtls/wolfssl.c index f6e1e6446a..9d5366dfe7 100644 --- a/lib/vtls/wolfssl.c +++ b/lib/vtls/wolfssl.c @@ -1759,7 +1759,7 @@ static CURLcode wssl_handshake(struct Curl_cfilter *cf, } } #ifdef USE_ECH_WOLFSSL - else if(-1 == detail) { + else if(detail == -1) { /* try access a retry_config ECHConfigList for tracing */ byte echConfigs[1000]; word32 echConfigsLen = 1000; diff --git a/src/tool_dirhie.c b/src/tool_dirhie.c index 24759a642b..2c8aba362b 100644 --- a/src/tool_dirhie.c +++ b/src/tool_dirhie.c @@ -126,7 +126,7 @@ CURLcode create_dir_hierarchy(const char *outfile, struct GlobalConfig *global) /* Create directory. Ignore access denied error to allow traversal. */ /* !checksrc! disable ERRNOVAR 1 */ - if(!skip && (-1 == mkdir(curlx_dyn_ptr(&dirbuf), (mode_t)0000750)) && + if(!skip && (mkdir(curlx_dyn_ptr(&dirbuf), (mode_t)0000750) == -1) && (errno != EACCES) && (errno != EEXIST)) { show_dir_errno(global, curlx_dyn_ptr(&dirbuf)); result = CURLE_WRITE_ERROR; diff --git a/src/tool_filetime.c b/src/tool_filetime.c index f4ff3a4291..d94df35346 100644 --- a/src/tool_filetime.c +++ b/src/tool_filetime.c @@ -76,7 +76,7 @@ int getfiletime(const char *filename, struct GlobalConfig *global, } #else struct_stat statbuf; - if(-1 != stat(filename, &statbuf)) { + if(stat(filename, &statbuf) != -1) { *stamp = (curl_off_t)statbuf.st_mtime; rc = 0; } diff --git a/src/tool_getparam.c b/src/tool_getparam.c index c78494f76d..f45959068f 100644 --- a/src/tool_getparam.c +++ b/src/tool_getparam.c @@ -1585,7 +1585,7 @@ static ParameterError parse_time_cond(struct OperationConfig *config, break; } config->condtime = (curl_off_t)curl_getdate(nextarg, NULL); - if(-1 == config->condtime) { + if(config->condtime == -1) { curl_off_t value; /* now let's see if it is a filename to get the time from instead! */ int rc = getfiletime(nextarg, config->global, &value); diff --git a/src/tool_getpass.c b/src/tool_getpass.c index eea46fb526..fc59accc07 100644 --- a/src/tool_getpass.c +++ b/src/tool_getpass.c @@ -179,7 +179,7 @@ char *getpass_r(const char *prompt, /* prompt to display */ ssize_t nread; bool disabled; int fd = open("/dev/tty", O_RDONLY); - if(-1 == fd) + if(fd == -1) fd = STDIN_FILENO; /* use stdin if the tty could not be used */ disabled = ttyecho(FALSE, fd); /* disable terminal echo */ diff --git a/src/tool_msgs.c b/src/tool_msgs.c index 294e27ad43..8c954cced0 100644 --- a/src/tool_msgs.c +++ b/src/tool_msgs.c @@ -66,7 +66,7 @@ static void voutf(struct GlobalConfig *global, while(!ISBLANK(ptr[cut]) && cut) { cut--; } - if(0 == cut) + if(cut == 0) /* not a single cutting position was found, just cut it at the max text width then! */ cut = width-1; diff --git a/src/tool_operate.c b/src/tool_operate.c index 7abad907bc..764c98b587 100644 --- a/src/tool_operate.c +++ b/src/tool_operate.c @@ -1009,7 +1009,7 @@ static CURLcode setup_outfile(struct OperationConfig *config, of the file as it is now and open it for append instead */ struct_stat fileinfo; /* VMS -- Danger, the filesize is only valid for stream files */ - if(0 == stat(per->outfile, &fileinfo)) + if(stat(per->outfile, &fileinfo) == 0) /* set offset to current file size: */ config->resume_from = fileinfo.st_size; else diff --git a/tests/libtest/lib1560.c b/tests/libtest/lib1560.c index 26a98de286..62e1cdd6d5 100644 --- a/tests/libtest/lib1560.c +++ b/tests/libtest/lib1560.c @@ -1194,7 +1194,7 @@ static CURLUcode updateurl(CURLU *u, const char *cmd, unsigned int setflags) memset(value, 0, sizeof(value)); /* Avoid valgrind false positive. */ memcpy(buf, p, n); buf[n] = 0; - if(2 == sscanf(buf, "%79[^=]=%79[^,]", part, value)) { + if(sscanf(buf, "%79[^=]=%79[^,]", part, value) == 2) { CURLUPart what = part2id(part); #if 0 /* for debugging this */ @@ -1888,8 +1888,8 @@ static int clear_url(void) curl_mfprintf(stderr, "unexpected return code line %u\n", __LINE__); rc = curl_url_get(u, clear_url_list[i].part, &p, 0); - if(rc != clear_url_list[i].ucode || (clear_url_list[i].out && - 0 != strcmp(p, clear_url_list[i].out))) { + if(rc != clear_url_list[i].ucode || + (clear_url_list[i].out && strcmp(p, clear_url_list[i].out) != 0)) { curl_mfprintf(stderr, "unexpected return code line %u\n", __LINE__); error++; diff --git a/tests/server/dnsd.c b/tests/server/dnsd.c index 389c066c82..745fbeb59b 100644 --- a/tests/server/dnsd.c +++ b/tests/server/dnsd.c @@ -477,8 +477,8 @@ static int test_dnsd(int argc, char **argv) } flag = 1; - if(0 != setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, - (void *)&flag, sizeof(flag))) { + if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, + (void *)&flag, sizeof(flag))) { error = SOCKERRNO; logmsg("setsockopt(SO_REUSEADDR) failed with error (%d) %s", error, sstrerror(error)); diff --git a/tests/server/mqttd.c b/tests/server/mqttd.c index 76ef715011..8bdf0a5fe4 100644 --- a/tests/server/mqttd.c +++ b/tests/server/mqttd.c @@ -81,7 +81,7 @@ static void mqttd_getconfig(void) while(fgets(buffer, sizeof(buffer), fp)) { char key[32]; char value[32]; - if(2 == sscanf(buffer, "%31s %31s", key, value)) { + if(sscanf(buffer, "%31s %31s", key, value) == 2) { if(!strcmp(key, "version")) { m_config.version = byteval(value); logmsg("version [%d] set", m_config.version); diff --git a/tests/server/rtspd.c b/tests/server/rtspd.c index 7f1ce81022..b6dd5ead1e 100644 --- a/tests/server/rtspd.c +++ b/tests/server/rtspd.c @@ -269,7 +269,7 @@ static int rtspd_ProcessRequest(struct rtspd_httprequest *req) logmsg("instructed to stream"); req->rcmd = RCMD_STREAM; } - else if(1 == sscanf(ptr, "pipe: %d", &num)) { + else if(sscanf(ptr, "pipe: %d", &num) == 1) { logmsg("instructed to allow a pipe size of %d", num); if(num < 0) logmsg("negative pipe size ignored"); @@ -277,7 +277,7 @@ static int rtspd_ProcessRequest(struct rtspd_httprequest *req) req->pipe = num-1; /* decrease by one since we don't count the first request in this number */ } - else if(1 == sscanf(ptr, "skip: %d", &num)) { + else if(sscanf(ptr, "skip: %d", &num) == 1) { logmsg("instructed to skip this number of bytes %d", num); req->skip = num; } @@ -784,7 +784,7 @@ static int rtspd_send_doc(curl_socket_t sock, struct rtspd_httprequest *req) else { FILE *stream = test2fopen(req->testno, logdir); char partbuf[80]="data"; - if(0 != req->partno) + if(req->partno) snprintf(partbuf, sizeof(partbuf), "data%ld", req->partno); if(!stream) { error = errno; @@ -935,7 +935,7 @@ static int rtspd_send_doc(curl_socket_t sock, struct rtspd_httprequest *req) int num; ptr = cmd; do { - if(2 == sscanf(ptr, "%31s %d", command, &num)) { + if(sscanf(ptr, "%31s %d", command, &num) == 2) { if(!strcmp("wait", command)) { logmsg("Told to sleep for %d seconds", num); quarters = num * 4; @@ -1099,8 +1099,8 @@ static int test_rtspd(int argc, char *argv[]) } flag = 1; - if(0 != setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, - (void *)&flag, sizeof(flag))) { + if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, + (void *)&flag, sizeof(flag))) { error = SOCKERRNO; logmsg("setsockopt(SO_REUSEADDR) failed with error (%d) %s", error, sstrerror(error)); diff --git a/tests/server/socksd.c b/tests/server/socksd.c index 70e27af2ff..eb681bc947 100644 --- a/tests/server/socksd.c +++ b/tests/server/socksd.c @@ -122,7 +122,7 @@ static void socksd_getconfig(void) while(fgets(buffer, sizeof(buffer), fp)) { char key[32]; char value[260]; - if(2 == sscanf(buffer, "%31s %259s", key, value)) { + if(sscanf(buffer, "%31s %259s", key, value) == 2) { if(!strcmp(key, "version")) { s_config.version = byteval(value); logmsg("version [%d] set", s_config.version); diff --git a/tests/server/sws.c b/tests/server/sws.c index f49f22339d..1572c2855f 100644 --- a/tests/server/sws.c +++ b/tests/server/sws.c @@ -183,7 +183,7 @@ static int parse_cmdfile(struct sws_httprequest *req) int testnum = DOCNUMBER_NOTHING; char buf[256]; while(fgets(buf, sizeof(buf), f)) { - if(1 == sscanf(buf, "Testnum %d", &testnum)) { + if(sscanf(buf, "Testnum %d", &testnum) == 1) { logmsg("[%s] cmdfile says testnum %d", cmdfile, testnum); req->testno = testnum; } @@ -255,7 +255,7 @@ static int sws_parse_servercmd(struct sws_httprequest *req) logmsg("swsclose: close this connection after response"); req->close = TRUE; } - else if(1 == sscanf(cmd, "skip: %d", &num)) { + else if(sscanf(cmd, "skip: %d", &num) == 1) { logmsg("instructed to skip this number of bytes %d", num); req->skip = num; } @@ -263,11 +263,11 @@ static int sws_parse_servercmd(struct sws_httprequest *req) logmsg("instructed to reject Expect: 100-continue"); req->noexpect = TRUE; } - else if(1 == sscanf(cmd, "delay: %d", &num)) { + else if(sscanf(cmd, "delay: %d", &num) == 1) { logmsg("instructed to delay %d msecs after connect", num); req->delay = num; } - else if(1 == sscanf(cmd, "writedelay: %d", &num)) { + else if(sscanf(cmd, "writedelay: %d", &num) == 1) { logmsg("instructed to delay %d msecs between packets", num); req->writedelay = num; } @@ -1171,7 +1171,7 @@ retry: int num; ptr = cmd; do { - if(2 == sscanf(ptr, "%31s %d", command, &num)) { + if(sscanf(ptr, "%31s %d", command, &num) == 2) { if(!strcmp("wait", command)) { logmsg("Told to sleep for %d seconds", num); quarters = num * 4; @@ -1243,8 +1243,8 @@ static curl_socket_t connect_to(const char *ipaddr, unsigned short port) if(socket_domain_is_ip()) { /* Disable the Nagle algorithm */ curl_socklen_t flag = 1; - if(0 != setsockopt(serverfd, IPPROTO_TCP, TCP_NODELAY, - (void *)&flag, sizeof(flag))) + if(setsockopt(serverfd, IPPROTO_TCP, TCP_NODELAY, + (void *)&flag, sizeof(flag))) logmsg("====> TCP_NODELAY for server connection failed"); } #endif @@ -1252,7 +1252,7 @@ static curl_socket_t connect_to(const char *ipaddr, unsigned short port) /* We want to do the connect() in a non-blocking mode, since * Windows has an internal retry logic that may lead to long * timeouts if the peer is not listening. */ - if(0 != curlx_nonblock(serverfd, TRUE)) { + if(curlx_nonblock(serverfd, TRUE)) { error = SOCKERRNO; logmsg("curlx_nonblock(TRUE) failed with error (%d) %s", error, sstrerror(error)); @@ -1321,10 +1321,10 @@ static curl_socket_t connect_to(const char *ipaddr, unsigned short port) goto error; else if(rc > 0) { curl_socklen_t errSize = sizeof(error); - if(0 != getsockopt(serverfd, SOL_SOCKET, SO_ERROR, - (void *)&error, &errSize)) + if(getsockopt(serverfd, SOL_SOCKET, SO_ERROR, + (void *)&error, &errSize)) error = SOCKERRNO; - if((0 == error) || (SOCKEISCONN == error)) + if((error == 0) || (SOCKEISCONN == error)) goto success; else if((error != SOCKEINPROGRESS) && (error != SOCKEWOULDBLOCK)) goto error; @@ -1346,7 +1346,7 @@ success: logmsg("connected fine to %s%s%s:%hu, now tunnel", op_br, ipaddr, cl_br, port); - if(0 != curlx_nonblock(serverfd, FALSE)) { + if(curlx_nonblock(serverfd, FALSE)) { error = SOCKERRNO; logmsg("curlx_nonblock(FALSE) failed with error (%d) %s", error, sstrerror(error)); @@ -1549,8 +1549,8 @@ static void http_connect(curl_socket_t *infdp, if(socket_domain_is_ip()) { /* Disable the Nagle algorithm */ curl_socklen_t flag = 1; - if(0 != setsockopt(datafd, IPPROTO_TCP, TCP_NODELAY, - (void *)&flag, sizeof(flag))) + if(setsockopt(datafd, IPPROTO_TCP, TCP_NODELAY, + (void *)&flag, sizeof(flag))) logmsg("====> TCP_NODELAY for client DATA connection failed"); } #endif @@ -1839,7 +1839,7 @@ static curl_socket_t accept_connection(curl_socket_t sock) return CURL_SOCKET_BAD; } - if(0 != curlx_nonblock(msgsock, TRUE)) { + if(curlx_nonblock(msgsock, TRUE)) { error = SOCKERRNO; logmsg("curlx_nonblock failed with error (%d) %s", error, sstrerror(error)); @@ -1847,8 +1847,8 @@ static curl_socket_t accept_connection(curl_socket_t sock) return CURL_SOCKET_BAD; } - if(0 != setsockopt(msgsock, SOL_SOCKET, SO_KEEPALIVE, - (void *)&flag, sizeof(flag))) { + if(setsockopt(msgsock, SOL_SOCKET, SO_KEEPALIVE, + (void *)&flag, sizeof(flag))) { error = SOCKERRNO; logmsg("setsockopt(SO_KEEPALIVE) failed with error (%d) %s", error, sstrerror(error)); @@ -1877,8 +1877,8 @@ static curl_socket_t accept_connection(curl_socket_t sock) * Disable the Nagle algorithm to make it easier to send out a large * response in many small segments to torture the clients more. */ - if(0 != setsockopt(msgsock, IPPROTO_TCP, TCP_NODELAY, - (void *)&flag, sizeof(flag))) + if(setsockopt(msgsock, IPPROTO_TCP, TCP_NODELAY, + (void *)&flag, sizeof(flag))) logmsg("====> TCP_NODELAY failed"); } #endif @@ -2162,14 +2162,14 @@ static int test_sws(int argc, char *argv[]) } flag = 1; - if(0 != setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, - (void *)&flag, sizeof(flag))) { + if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, + (void *)&flag, sizeof(flag))) { error = SOCKERRNO; logmsg("setsockopt(SO_REUSEADDR) failed with error (%d) %s", error, sstrerror(error)); goto sws_cleanup; } - if(0 != curlx_nonblock(sock, TRUE)) { + if(curlx_nonblock(sock, TRUE)) { error = SOCKERRNO; logmsg("curlx_nonblock failed with error (%d) %s", error, sstrerror(error)); diff --git a/tests/server/tftpd.c b/tests/server/tftpd.c index bd2d42bd6f..1f14ee67a5 100644 --- a/tests/server/tftpd.c +++ b/tests/server/tftpd.c @@ -481,7 +481,7 @@ static ssize_t write_behind(struct testcase *test, int convert) } /* formerly putc(c, file); */ - if(1 != write(test->ofile, &c, 1)) + if(write(test->ofile, &c, 1) != 1) break; skipit: prevchar = c; @@ -662,8 +662,8 @@ static int test_tftpd(int argc, char **argv) } flag = 1; - if(0 != setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, - (void *)&flag, sizeof(flag))) { + if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, + (void *)&flag, sizeof(flag))) { error = SOCKERRNO; logmsg("setsockopt(SO_REUSEADDR) failed with error (%d) %s", error, sstrerror(error)); @@ -1029,7 +1029,7 @@ static int tftpd_parse_servercmd(struct testcase *req) cmd = orgcmd; while(cmd && cmdsize) { char *check; - if(1 == sscanf(cmd, "writedelay: %d", &num)) { + if(sscanf(cmd, "writedelay: %d", &num) == 1) { logmsg("instructed to delay %d secs between packets", num); req->writedelay = num; } @@ -1118,7 +1118,7 @@ static int validate_access(struct testcase *test, stream = test2fopen(testno, logdir); - if(0 != partno) + if(partno) snprintf(partbuf, sizeof(partbuf), "data%ld", partno); if(!stream) {