mirror of
https://github.com/curl/curl.git
synced 2026-07-28 19:43:07 +03:00
tidy-up: drop stray comparisons with literal zero
Drop from: - strcmp, strcmpi, strncmp, memcmp, lstat, getrlimit, setrlimit, fseek, fstat - autotools detection snippets. - smooth-gtk-thread: simplify `!var != 0` expression. Closes #21947
This commit is contained in:
parent
2f3fa479dd
commit
97aed9c960
43 changed files with 142 additions and 143 deletions
|
|
@ -79,7 +79,7 @@ int cgetopt(int argc, const char * const argv[], const char *optstring)
|
|||
}
|
||||
|
||||
arg = argv[coptind];
|
||||
if(arg && strcmp(arg, "--") == 0) {
|
||||
if(arg && !strcmp(arg, "--")) {
|
||||
coptind++;
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -248,7 +248,7 @@ int main(int argc, const char **argv)
|
|||
entry_name = argv[1];
|
||||
entry_func = NULL;
|
||||
for(tmp = 0; s_entries[tmp].ptr; ++tmp) {
|
||||
if(strcmp(entry_name, s_entries[tmp].name) == 0) {
|
||||
if(!strcmp(entry_name, s_entries[tmp].name)) {
|
||||
entry_func = s_entries[tmp].ptr;
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ static CURLcode test_lib1536(const char *URL)
|
|||
__FILE__, __LINE__, (int)result, curl_easy_strerror(result));
|
||||
goto test_cleanup;
|
||||
}
|
||||
if(!scheme || memcmp(scheme, "http", 5) != 0) {
|
||||
if(!scheme || memcmp(scheme, "http", 5)) {
|
||||
curl_mfprintf(stderr, "%s:%d scheme of http resource is incorrect; "
|
||||
"expected 'http' but is %s\n",
|
||||
__FILE__, __LINE__, scheme ? "invalid" : "NULL");
|
||||
|
|
|
|||
|
|
@ -2135,7 +2135,7 @@ static int clear_url(void)
|
|||
|
||||
rc = curl_url_get(u, clear_url_list[i].part, &p, 0);
|
||||
if(rc != clear_url_list[i].ucode ||
|
||||
(p && clear_url_list[i].out && strcmp(p, clear_url_list[i].out) != 0)) {
|
||||
(p && clear_url_list[i].out && strcmp(p, clear_url_list[i].out))) {
|
||||
|
||||
curl_mfprintf(stderr, "unexpected return code line %d\n", __LINE__);
|
||||
error++;
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ static bool is_chain_in_order(struct curl_certinfo *cert_info)
|
|||
if(last_issuer) {
|
||||
/* If the last certificate's issuer matches the current certificate's
|
||||
* subject, then the chain is in order */
|
||||
if(strcmp(last_issuer, subject) != 0) {
|
||||
if(strcmp(last_issuer, subject)) {
|
||||
curl_mfprintf(stderr,
|
||||
"cert %d issuer does not match cert %d subject\n",
|
||||
cert - 1, cert);
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ static int t518_test_rlimit(int keep_open)
|
|||
|
||||
/* get initial open file limits */
|
||||
|
||||
if(getrlimit(RLIMIT_NOFILE, &rl) != 0) {
|
||||
if(getrlimit(RLIMIT_NOFILE, &rl)) {
|
||||
t518_store_errmsg("getrlimit() failed", errno);
|
||||
curl_mfprintf(stderr, "%s\n", t518_msgbuff);
|
||||
return -1;
|
||||
|
|
@ -135,7 +135,7 @@ static int t518_test_rlimit(int keep_open)
|
|||
(rl.rlim_cur < OPEN_MAX)) {
|
||||
curl_mfprintf(stderr, "raising soft limit up to OPEN_MAX\n");
|
||||
rl.rlim_cur = OPEN_MAX;
|
||||
if(setrlimit(RLIMIT_NOFILE, &rl) != 0) {
|
||||
if(setrlimit(RLIMIT_NOFILE, &rl)) {
|
||||
/* on failure do not abort, only issue a warning */
|
||||
t518_store_errmsg("setrlimit() failed", errno);
|
||||
curl_mfprintf(stderr, "%s\n", t518_msgbuff);
|
||||
|
|
@ -146,7 +146,7 @@ static int t518_test_rlimit(int keep_open)
|
|||
|
||||
curl_mfprintf(stderr, "raising soft limit up to hard limit\n");
|
||||
rl.rlim_cur = rl.rlim_max;
|
||||
if(setrlimit(RLIMIT_NOFILE, &rl) != 0) {
|
||||
if(setrlimit(RLIMIT_NOFILE, &rl)) {
|
||||
/* on failure do not abort, only issue a warning */
|
||||
t518_store_errmsg("setrlimit() failed", errno);
|
||||
curl_mfprintf(stderr, "%s\n", t518_msgbuff);
|
||||
|
|
@ -155,7 +155,7 @@ static int t518_test_rlimit(int keep_open)
|
|||
|
||||
/* get current open file limits */
|
||||
|
||||
if(getrlimit(RLIMIT_NOFILE, &rl) != 0) {
|
||||
if(getrlimit(RLIMIT_NOFILE, &rl)) {
|
||||
t518_store_errmsg("getrlimit() failed", errno);
|
||||
curl_mfprintf(stderr, "%s\n", t518_msgbuff);
|
||||
return -3;
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ static int t537_test_rlimit(int keep_open)
|
|||
|
||||
/* get initial open file limits */
|
||||
|
||||
if(getrlimit(RLIMIT_NOFILE, &rl) != 0) {
|
||||
if(getrlimit(RLIMIT_NOFILE, &rl)) {
|
||||
t537_store_errmsg("getrlimit() failed", errno);
|
||||
curl_mfprintf(stderr, "%s\n", t537_msgbuff);
|
||||
return -1;
|
||||
|
|
@ -136,7 +136,7 @@ static int t537_test_rlimit(int keep_open)
|
|||
(rl.rlim_cur < OPEN_MAX)) {
|
||||
curl_mfprintf(stderr, "raising soft limit up to OPEN_MAX\n");
|
||||
rl.rlim_cur = OPEN_MAX;
|
||||
if(setrlimit(RLIMIT_NOFILE, &rl) != 0) {
|
||||
if(setrlimit(RLIMIT_NOFILE, &rl)) {
|
||||
/* on failure do not abort, only issue a warning */
|
||||
t537_store_errmsg("setrlimit() failed", errno);
|
||||
curl_mfprintf(stderr, "%s\n", t537_msgbuff);
|
||||
|
|
@ -147,7 +147,7 @@ static int t537_test_rlimit(int keep_open)
|
|||
|
||||
curl_mfprintf(stderr, "raising soft limit up to hard limit\n");
|
||||
rl.rlim_cur = rl.rlim_max;
|
||||
if(setrlimit(RLIMIT_NOFILE, &rl) != 0) {
|
||||
if(setrlimit(RLIMIT_NOFILE, &rl)) {
|
||||
/* on failure do not abort, only issue a warning */
|
||||
t537_store_errmsg("setrlimit() failed", errno);
|
||||
curl_mfprintf(stderr, "%s\n", t537_msgbuff);
|
||||
|
|
@ -156,7 +156,7 @@ static int t537_test_rlimit(int keep_open)
|
|||
|
||||
/* get current open file limits */
|
||||
|
||||
if(getrlimit(RLIMIT_NOFILE, &rl) != 0) {
|
||||
if(getrlimit(RLIMIT_NOFILE, &rl)) {
|
||||
t537_store_errmsg("getrlimit() failed", errno);
|
||||
curl_mfprintf(stderr, "%s\n", t537_msgbuff);
|
||||
return -3;
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ static size_t rtp_write(char *data, size_t size, size_t nmemb, void *stream)
|
|||
data += 4;
|
||||
for(i = 0; i < message_size; i += RTP_DATA_SIZE) {
|
||||
if(message_size - i > RTP_DATA_SIZE) {
|
||||
if(memcmp(RTP_DATA, data + i, RTP_DATA_SIZE) != 0) {
|
||||
if(memcmp(RTP_DATA, data + i, RTP_DATA_SIZE)) {
|
||||
curl_mprintf("RTP PAYLOAD CORRUPTED [%s]\n", data + i);
|
||||
#if 0
|
||||
return failure;
|
||||
|
|
@ -75,7 +75,7 @@ static size_t rtp_write(char *data, size_t size, size_t nmemb, void *stream)
|
|||
}
|
||||
}
|
||||
else {
|
||||
if(memcmp(RTP_DATA, data + i, message_size - i) != 0) {
|
||||
if(memcmp(RTP_DATA, data + i, message_size - i)) {
|
||||
curl_mprintf("RTP PAYLOAD END CORRUPTED (%d), [%s]\n",
|
||||
message_size - i, data + i);
|
||||
#if 0
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ static long chunk_bgn(const void *f, void *ptr, int remains)
|
|||
"-------------------------------------------"
|
||||
"------------------\n");
|
||||
}
|
||||
if(strcmp(finfo->filename, "someothertext.txt") == 0) {
|
||||
if(!strcmp(finfo->filename, "someothertext.txt")) {
|
||||
curl_mprintf("# THIS CONTENT WAS SKIPPED IN CHUNK_BGN CALLBACK #\n");
|
||||
return CURL_CHUNK_BGN_FUNC_SKIP;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ int main(int argc, const char **argv)
|
|||
entry_name = argv[1];
|
||||
entry_func = NULL;
|
||||
for(tmp = 0; s_entries[tmp].ptr; ++tmp) {
|
||||
if(strcmp(entry_name, s_entries[tmp].name) == 0) {
|
||||
if(!strcmp(entry_name, s_entries[tmp].name)) {
|
||||
entry_func = s_entries[tmp].ptr;
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -970,7 +970,7 @@ static int do_tftp(struct testcase *test, struct tftphdr *tp, ssize_t size)
|
|||
curlx_fclose(server);
|
||||
|
||||
for(pf = formata; pf->f_mode; pf++)
|
||||
if(strcmp(pf->f_mode, mode) == 0)
|
||||
if(!strcmp(pf->f_mode, mode))
|
||||
break;
|
||||
if(!pf->f_mode) {
|
||||
nak(TFTP_EBADOP);
|
||||
|
|
|
|||
|
|
@ -119,10 +119,10 @@ static CURLcode test_unit1304(const char *arg)
|
|||
Curl_netrc_init(&store);
|
||||
res = Curl_netrc_scan(data, &store, "example.com", NULL, arg, &cr_out);
|
||||
fail_unless(res == NETRC_OK, "Host should have been found");
|
||||
fail_unless(strncmp(Curl_creds_passwd(cr_out), "passwd", 6) == 0,
|
||||
fail_unless(!strncmp(Curl_creds_passwd(cr_out), "passwd", 6),
|
||||
"password should be 'passwd'");
|
||||
fail_unless(!t1304_no_user(cr_out), "returned NULL!");
|
||||
fail_unless(strncmp(Curl_creds_user(cr_out), "admin", 5) == 0,
|
||||
fail_unless(!strncmp(Curl_creds_user(cr_out), "admin", 5),
|
||||
"login should be 'admin'");
|
||||
Curl_netrc_cleanup(&store);
|
||||
|
||||
|
|
@ -132,10 +132,10 @@ static CURLcode test_unit1304(const char *arg)
|
|||
Curl_netrc_init(&store);
|
||||
res = Curl_netrc_scan(data, &store, "curl.example.com", NULL, arg, &cr_out);
|
||||
fail_unless(res == NETRC_OK, "Host should have been found");
|
||||
fail_unless(strncmp(Curl_creds_passwd(cr_out), "none", 4) == 0,
|
||||
fail_unless(!strncmp(Curl_creds_passwd(cr_out), "none", 4),
|
||||
"password should be 'none'");
|
||||
fail_unless(!t1304_no_user(cr_out), "returned NULL!");
|
||||
fail_unless(strncmp(Curl_creds_user(cr_out), "none", 4) == 0,
|
||||
fail_unless(!strncmp(Curl_creds_user(cr_out), "none", 4),
|
||||
"login should be 'none'");
|
||||
Curl_netrc_cleanup(&store);
|
||||
|
||||
|
|
|
|||
|
|
@ -50,13 +50,13 @@ static void t1620_parse(const char *input,
|
|||
|
||||
if(!unitfail) {
|
||||
fail_unless(!userstr || !exp_username ||
|
||||
strcmp(userstr, exp_username) == 0,
|
||||
!strcmp(userstr, exp_username),
|
||||
"userstr should be equal to exp_username");
|
||||
fail_unless(!passwdstr || !exp_password ||
|
||||
strcmp(passwdstr, exp_password) == 0,
|
||||
!strcmp(passwdstr, exp_password),
|
||||
"passwdstr should be equal to exp_password");
|
||||
fail_unless(!options || !exp_options ||
|
||||
strcmp(options, exp_options) == 0,
|
||||
!strcmp(options, exp_options),
|
||||
"options should be equal to exp_options");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,11 +56,11 @@ static void t1663_parse(const char *input_data,
|
|||
fail_unless(!!exp_host == !!host, "host expectation failed");
|
||||
|
||||
if(!unitfail) {
|
||||
fail_unless(!dev || !exp_dev || strcmp(dev, exp_dev) == 0,
|
||||
fail_unless(!dev || !exp_dev || !strcmp(dev, exp_dev),
|
||||
"dev should be equal to exp_dev");
|
||||
fail_unless(!iface || !exp_iface || strcmp(iface, exp_iface) == 0,
|
||||
fail_unless(!iface || !exp_iface || !strcmp(iface, exp_iface),
|
||||
"iface should be equal to exp_iface");
|
||||
fail_unless(!host || !exp_host || strcmp(host, exp_host) == 0,
|
||||
fail_unless(!host || !exp_host || !strcmp(host, exp_host),
|
||||
"host should be equal to exp_host");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -92,23 +92,22 @@ static CURLcode test_unit1676(const char *arg)
|
|||
if(result == CURLE_OK) {
|
||||
/* Walk certinfo entries to find dh(p), dh(g), and dh(pub_key) */
|
||||
for(slist = data->info.certs.certinfo[0]; slist; slist = slist->next) {
|
||||
if(strncmp(slist->data, "dh(p):", 6) == 0)
|
||||
if(!strncmp(slist->data, "dh(p):", 6))
|
||||
dhp_value = slist->data + 6;
|
||||
else if(strncmp(slist->data, "dh(g):", 6) == 0)
|
||||
else if(!strncmp(slist->data, "dh(g):", 6))
|
||||
dhg_value = slist->data + 6;
|
||||
else if(strncmp(slist->data, "dh(pub_key):", 12) == 0)
|
||||
else if(!strncmp(slist->data, "dh(pub_key):", 12))
|
||||
dhpk_value = slist->data + 12;
|
||||
}
|
||||
|
||||
abort_unless(dhp_value, "dh(p) not found in certinfo");
|
||||
abort_unless(dhg_value, "dh(g) not found in certinfo");
|
||||
abort_unless(dhpk_value, "dh(pub_key) not found in certinfo");
|
||||
fail_if(strcmp(dhp_value, dhg_value) == 0,
|
||||
fail_if(!strcmp(dhp_value, dhg_value),
|
||||
"dh(p) and dh(g) have the same value (bug: g re-reads p)");
|
||||
fail_unless(strcmp(dhp_value, "17") == 0, "dh(p) expected 17 (0x11)");
|
||||
fail_unless(strcmp(dhg_value, "34") == 0, "dh(g) expected 34 (0x22)");
|
||||
fail_unless(strcmp(dhpk_value, "51") == 0,
|
||||
"dh(pub_key) expected 51 (0x33)");
|
||||
fail_unless(!strcmp(dhp_value, "17"), "dh(p) expected 17 (0x11)");
|
||||
fail_unless(!strcmp(dhg_value, "34"), "dh(g) expected 34 (0x22)");
|
||||
fail_unless(!strcmp(dhpk_value, "51"), "dh(pub_key) expected 51 (0x33)");
|
||||
}
|
||||
|
||||
curl_easy_cleanup(data);
|
||||
|
|
|
|||
|
|
@ -544,7 +544,7 @@ static CURLcode test_unit3205(const char *arg)
|
|||
|
||||
Curl_cipher_suite_get_str(test->id, buf, sizeof(buf), TRUE);
|
||||
|
||||
if(expect && strcmp(buf, expect) != 0) {
|
||||
if(expect && strcmp(buf, expect)) {
|
||||
curl_mfprintf(stderr, "Curl_cipher_suite_get_str FAILED for 0x%04x, "
|
||||
"result = \"%s\", expected = \"%s\"\n",
|
||||
test->id, buf, expect);
|
||||
|
|
@ -559,17 +559,17 @@ static CURLcode test_unit3205(const char *arg)
|
|||
|
||||
/* suites matched by EDH alias will return the DHE name */
|
||||
if(test->id >= 0x0011 && test->id < 0x0017) {
|
||||
if(expect && memcmp(expect, "EDH-", 4) == 0) {
|
||||
if(expect && !memcmp(expect, "EDH-", 4)) {
|
||||
curlx_strcopy(alt, sizeof(alt), expect, strlen(expect));
|
||||
expect = (const char *)memcpy(alt, "DHE-", sizeof("DHE-") - 1);
|
||||
}
|
||||
if(expect && memcmp(expect + 4, "EDH-", 4) == 0) {
|
||||
if(expect && !memcmp(expect + 4, "EDH-", 4)) {
|
||||
curlx_strcopy(alt, sizeof(alt), expect, strlen(expect));
|
||||
expect = (const char *)memcpy(alt + 4, "DHE-", sizeof("DHE-") - 1) - 4;
|
||||
}
|
||||
}
|
||||
|
||||
if(expect && strcmp(buf, expect) != 0) {
|
||||
if(expect && strcmp(buf, expect)) {
|
||||
curl_mfprintf(stderr, "Curl_cipher_suite_get_str FAILED for 0x%04x, "
|
||||
"result = \"%s\", expected = \"%s\"\n",
|
||||
test->id, buf, expect);
|
||||
|
|
@ -598,7 +598,7 @@ static CURLcode test_unit3205(const char *arg)
|
|||
test->str, id, test->id);
|
||||
unitfail++;
|
||||
}
|
||||
if(len > 64 || strncmp(ptr, test->str, len) != 0) {
|
||||
if(len > 64 || strncmp(ptr, test->str, len)) {
|
||||
curl_mfprintf(stderr, "Curl_cipher_suite_walk_str ABORT for \"%s\" "
|
||||
"unexpected pointers\n",
|
||||
test->str);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue