diff options
author | Marcel Raad <Marcel.Raad@teamviewer.com> | 2019-05-25 10:06:08 +0200 |
---|---|---|
committer | Marcel Raad <Marcel.Raad@teamviewer.com> | 2019-06-05 20:38:06 +0200 |
commit | e23c52b3295a525fbaae9e7ed3e7061fea6dffc2 (patch) | |
tree | 4a74cf5ed3496a6126f1cc7c4284b6620108db06 /tests | |
parent | 04ac54e1965041684fc1b6532eba90f58601264e (diff) |
build: fix Codacy warnings
Reduce variable scopes and remove redundant variable stores.
Closes https://github.com/curl/curl/pull/3975
Diffstat (limited to 'tests')
-rw-r--r-- | tests/libtest/lib1541.c | 4 | ||||
-rw-r--r-- | tests/libtest/lib1560.c | 34 | ||||
-rw-r--r-- | tests/libtest/lib1905.c | 3 | ||||
-rw-r--r-- | tests/libtest/lib541.c | 2 | ||||
-rw-r--r-- | tests/libtest/lib569.c | 3 | ||||
-rw-r--r-- | tests/libtest/lib571.c | 3 | ||||
-rw-r--r-- | tests/server/socksd.c | 10 |
7 files changed, 25 insertions, 34 deletions
diff --git a/tests/libtest/lib1541.c b/tests/libtest/lib1541.c index 983a47e01..f3b41f5be 100644 --- a/tests/libtest/lib1541.c +++ b/tests/libtest/lib1541.c @@ -104,7 +104,6 @@ int test(char *URL) { pthread_t tid[NUM_THREADS]; int i; - int error; CURLSH *share; struct initurl url[NUM_THREADS]; @@ -119,6 +118,7 @@ int test(char *URL) init_locks(); for(i = 0; i< NUM_THREADS; i++) { + int error; url[i].url = URL; url[i].share = share; url[i].threadno = i; @@ -131,7 +131,7 @@ int test(char *URL) /* now wait for all threads to terminate */ for(i = 0; i< NUM_THREADS; i++) { - error = pthread_join(tid[i], NULL); + pthread_join(tid[i], NULL); fprintf(stderr, "Thread %d terminated\n", i); } diff --git a/tests/libtest/lib1560.c b/tests/libtest/lib1560.c index 1b72599ec..1185096d8 100644 --- a/tests/libtest/lib1560.c +++ b/tests/libtest/lib1560.c @@ -645,13 +645,11 @@ static struct redircase set_url_list[] = { static int set_url(void) { int i; - CURLUcode rc; - CURLU *urlp; int error = 0; for(i = 0; set_url_list[i].in && !error; i++) { - char *url = NULL; - urlp = curl_url(); + CURLUcode rc; + CURLU *urlp = curl_url(); if(!urlp) break; rc = curl_url_set(urlp, CURLUPART_URL, set_url_list[i].in, @@ -666,6 +664,7 @@ static int set_url(void) error++; } else { + char *url = NULL; rc = curl_url_get(urlp, CURLUPART_URL, &url, 0); if(rc) { fprintf(stderr, "%s:%d Get URL returned %d\n", @@ -677,8 +676,8 @@ static int set_url(void) error++; } } + curl_free(url); } - curl_free(url); } else if(rc != set_url_list[i].ucode) { fprintf(stderr, "Set URL\nin: %s\nreturned %d (expected %d)\n", @@ -693,11 +692,10 @@ static int set_url(void) static int set_parts(void) { int i; - CURLUcode rc; int error = 0; for(i = 0; set_parts_list[i].set && !error; i++) { - char *url = NULL; + CURLUcode rc; CURLU *urlp = curl_url(); if(!urlp) { error++; @@ -709,6 +707,7 @@ static int set_parts(void) else rc = CURLUE_OK; if(!rc) { + char *url = NULL; CURLUcode uc = updateurl(urlp, set_parts_list[i].set, set_parts_list[i].setflags); @@ -728,13 +727,13 @@ static int set_parts(void) else if(checkurl(url, set_parts_list[i].out)) { error++; } + curl_free(url); } else if(rc != set_parts_list[i].ucode) { fprintf(stderr, "Set parts\nin: %s\nreturned %d (expected %d)\n", set_parts_list[i].in, (int)rc, set_parts_list[i].ucode); error++; } - curl_free(url); curl_url_cleanup(urlp); } return error; @@ -743,10 +742,9 @@ static int set_parts(void) static int get_url(void) { int i; - CURLUcode rc; int error = 0; for(i = 0; get_url_list[i].in && !error; i++) { - char *url = NULL; + CURLUcode rc; CURLU *urlp = curl_url(); if(!urlp) { error++; @@ -755,6 +753,7 @@ static int get_url(void) rc = curl_url_set(urlp, CURLUPART_URL, get_url_list[i].in, get_url_list[i].urlflags); if(!rc) { + char *url = NULL; rc = curl_url_get(urlp, CURLUPART_URL, &url, get_url_list[i].getflags); if(rc) { @@ -767,13 +766,13 @@ static int get_url(void) error++; } } + curl_free(url); } else if(rc != get_url_list[i].ucode) { fprintf(stderr, "Get URL\nin: %s\nreturned %d (expected %d)\n", get_url_list[i].in, (int)rc, get_url_list[i].ucode); error++; } - curl_free(url); curl_url_cleanup(urlp); } return error; @@ -782,11 +781,10 @@ static int get_url(void) static int get_parts(void) { int i; - CURLUcode rc; - CURLU *urlp; int error = 0; for(i = 0; get_parts_list[i].in && !error; i++) { - urlp = curl_url(); + CURLUcode rc; + CURLU *urlp = curl_url(); if(!urlp) { error++; break; @@ -831,11 +829,10 @@ static struct querycase append_list[] = { static int append(void) { int i; - CURLUcode rc; - CURLU *urlp; int error = 0; for(i = 0; append_list[i].in && !error; i++) { - urlp = curl_url(); + CURLUcode rc; + CURLU *urlp = curl_url(); if(!urlp) { error++; break; @@ -881,12 +878,11 @@ static int append(void) static int scopeid(void) { - CURLU *u; + CURLU *u = curl_url(); int error = 0; CURLUcode rc; char *url; - u = curl_url(); rc = curl_url_set(u, CURLUPART_URL, "https://[fe80::20c:29ff:fe9c:409b%25eth0]/hello.html", 0); if(rc != CURLUE_OK) { diff --git a/tests/libtest/lib1905.c b/tests/libtest/lib1905.c index 79a50a782..7556d45e7 100644 --- a/tests/libtest/lib1905.c +++ b/tests/libtest/lib1905.c @@ -27,12 +27,11 @@ int test(char *URL) { - CURLM *cm = NULL; CURLSH *sh = NULL; CURL *ch = NULL; int unfinished; - cm = curl_multi_init(); + CURLM *cm = curl_multi_init(); if(!cm) return 1; sh = curl_share_init(); diff --git a/tests/libtest/lib541.c b/tests/libtest/lib541.c index 94a26a4b7..2861bfcc1 100644 --- a/tests/libtest/lib541.c +++ b/tests/libtest/lib541.c @@ -97,7 +97,7 @@ int test(char *URL) test_setopt(curl, CURLOPT_READDATA, hd_src); /* Now run off and do what you've been told! */ - res = curl_easy_perform(curl); + curl_easy_perform(curl); /* and now upload the exact same again, but without rewinding so it already is at end of file */ diff --git a/tests/libtest/lib569.c b/tests/libtest/lib569.c index 9c25db45d..3ddc10c4f 100644 --- a/tests/libtest/lib569.c +++ b/tests/libtest/lib569.c @@ -39,9 +39,8 @@ int test(char *URL) char *rtsp_session_id; int request = 1; int i; - FILE *idfile = NULL; - idfile = fopen(libtest_arg2, "wb"); + FILE *idfile = fopen(libtest_arg2, "wb"); if(idfile == NULL) { fprintf(stderr, "couldn't open the Session ID File\n"); return TEST_ERR_MAJOR_BAD; diff --git a/tests/libtest/lib571.c b/tests/libtest/lib571.c index c048747d9..f015f6bb2 100644 --- a/tests/libtest/lib571.c +++ b/tests/libtest/lib571.c @@ -104,9 +104,8 @@ int test(char *URL) CURL *curl; char *stream_uri = NULL; int request = 1; - FILE *protofile = NULL; - protofile = fopen(libtest_arg2, "wb"); + FILE *protofile = fopen(libtest_arg2, "wb"); if(protofile == NULL) { fprintf(stderr, "Couldn't open the protocol dump file\n"); return TEST_ERR_MAJOR_BAD; diff --git a/tests/server/socksd.c b/tests/server/socksd.c index df32a49a1..5e32bc904 100644 --- a/tests/server/socksd.c +++ b/tests/server/socksd.c @@ -749,10 +749,6 @@ static bool incoming(curl_socket_t listenfd) fd_set fds_read; fd_set fds_write; fd_set fds_err; - curl_socket_t sockfd = CURL_SOCKET_BAD; - int maxfd = -99; - ssize_t rc; - int error = 0; int clients = 0; /* connected clients */ struct perclient c[2]; @@ -772,15 +768,17 @@ static bool incoming(curl_socket_t listenfd) do { int i; + ssize_t rc; + int error = 0; + curl_socket_t sockfd = listenfd; + int maxfd = (int)sockfd; FD_ZERO(&fds_read); FD_ZERO(&fds_write); FD_ZERO(&fds_err); - sockfd = listenfd; /* there's always a socket to wait for */ FD_SET(sockfd, &fds_read); - maxfd = (int)sockfd; for(i = 0; i < 2; i++) { if(c[i].used) { |