mirror of
https://github.com/curl/curl.git
synced 2026-08-25 01:03:31 +03:00
build: fix Codacy warnings
Reduce variable scopes and remove redundant variable stores. Closes https://github.com/curl/curl/pull/3975
This commit is contained in:
parent
04ac54e196
commit
e23c52b329
23 changed files with 80 additions and 123 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue