Reduce variable scopes and remove redundant variable stores.
Closes https://github.com/curl/curl/pull/3975
#if defined(HAVE_GETHOSTBYADDR_R_5) || \
defined(HAVE_GETHOSTBYADDR_R_5_REENTRANT)
rc = gethostbyaddr_r(address, length, type, &h, &hdata);
+ (void)rc;
#elif defined(HAVE_GETHOSTBYADDR_R_7) || \
defined(HAVE_GETHOSTBYADDR_R_7_REENTRANT)
hp = gethostbyaddr_r(address, length, type, &h, buffer, 8192, &h_errnop);
#elif defined(HAVE_GETHOSTBYADDR_R_8) || \
defined(HAVE_GETHOSTBYADDR_R_8_REENTRANT)
rc = gethostbyaddr_r(address, length, type, &h, buffer, 8192, &hp, &h_errnop);
+ (void)rc;
#endif
#if defined(HAVE_GETHOSTBYNAME_R_3) || \
int main(int argc, char **argv)
{
- int rc = CURLE_OK;
-
/* curl easy handle */
CURL *handle;
struct callback_data data = { 0 };
/* global initialization */
- rc = curl_global_init(CURL_GLOBAL_ALL);
+ int rc = curl_global_init(CURL_GLOBAL_ALL);
if(rc)
return rc;
size_t SyncTime_CURL_WriteHeader(void *ptr, size_t size, size_t nmemb,
void *stream)
{
- int i, RetVal;
char TmpStr1[26], TmpStr2[26];
(void)stream;
TmpStr1 & 2? */
AutoSyncTime = 0;
else {
- RetVal = sscanf((char *)(ptr), "Date: %s %hu %s %hu %hu:%hu:%hu",
- TmpStr1, &SYSTime.wDay, TmpStr2, &SYSTime.wYear,
- &SYSTime.wHour, &SYSTime.wMinute, &SYSTime.wSecond);
+ int RetVal = sscanf((char *)(ptr), "Date: %s %hu %s %hu %hu:%hu:%hu",
+ TmpStr1, &SYSTime.wDay, TmpStr2, &SYSTime.wYear,
+ &SYSTime.wHour, &SYSTime.wMinute,
+ &SYSTime.wSecond);
if(RetVal == 7) {
+ int i;
SYSTime.wMilliseconds = 500; /* adjust to midpoint, 0.5 sec */
for(i = 0; i<12; i++) {
if(strcmp(MthStr[i], TmpStr2) == 0) {
const unsigned char *key_56)
{
const CK_MECHANISM_TYPE mech = CKM_DES_ECB; /* DES cipher in ECB mode */
- PK11SlotInfo *slot = NULL;
char key[8]; /* expanded 64 bit key */
SECItem key_item;
PK11SymKey *symkey = NULL;
bool rv = FALSE;
/* use internal slot for DES encryption (requires NSS to be initialized) */
- slot = PK11_GetInternalKeySlot();
+ PK11SlotInfo *slot = PK11_GetInternalKeySlot();
if(!slot)
return FALSE;
#ifdef HAVE_GSSAPI
char * const buf = data->state.buffer;
#endif
- CURLcode result = CURLE_OK;
int code;
-
- result = Curl_pp_readresp(sockfd, pp, &code, size);
+ CURLcode result = Curl_pp_readresp(sockfd, pp, &code, size);
#if defined(HAVE_GSSAPI)
/* handle the security-oriented responses 6xx ***/
static CURLcode ftp_state_retr_prequote(struct connectdata *conn)
{
- CURLcode result = CURLE_OK;
-
/* We've sent the TYPE, now we must send the list of prequote strings */
-
- result = ftp_state_quote(conn, TRUE, FTP_RETR_PREQUOTE);
-
- return result;
+ return ftp_state_quote(conn, TRUE, FTP_RETR_PREQUOTE);
}
static CURLcode ftp_state_stor_prequote(struct connectdata *conn)
{
- CURLcode result = CURLE_OK;
-
/* We've sent the TYPE, now we must send the list of prequote strings */
-
- result = ftp_state_quote(conn, TRUE, FTP_STOR_PREQUOTE);
-
- return result;
+ return ftp_state_quote(conn, TRUE, FTP_STOR_PREQUOTE);
}
static CURLcode ftp_state_type(struct connectdata *conn)
*/
static CURLcode imap_perform_starttls(struct connectdata *conn)
{
- CURLcode result = CURLE_OK;
-
/* Send the STARTTLS command */
- result = imap_sendf(conn, "STARTTLS");
+ CURLcode result = imap_sendf(conn, "STARTTLS");
if(!result)
state(conn, IMAP_STARTTLS);
*/
static CURLcode imap_perform_upgrade_tls(struct connectdata *conn)
{
- CURLcode result = CURLE_OK;
- struct imap_conn *imapc = &conn->proto.imapc;
-
/* Start the SSL connection */
- result = Curl_ssl_connect_nonblocking(conn, FIRSTSOCKET, &imapc->ssldone);
+ struct imap_conn *imapc = &conn->proto.imapc;
+ CURLcode result = Curl_ssl_connect_nonblocking(conn, FIRSTSOCKET,
+ &imapc->ssldone);
if(!result) {
if(imapc->state != IMAP_UPGRADETLS)
*/
static CURLcode imap_perform_logout(struct connectdata *conn)
{
- CURLcode result = CURLE_OK;
-
/* Send the LOGOUT command */
- result = imap_sendf(conn, "LOGOUT");
+ CURLcode result = imap_sendf(conn, "LOGOUT");
if(!result)
state(conn, IMAP_LOGOUT);
*/
static CURLcode pop3_perform_starttls(struct connectdata *conn)
{
- CURLcode result = CURLE_OK;
-
/* Send the STLS command */
- result = Curl_pp_sendf(&conn->proto.pop3c.pp, "%s", "STLS");
+ CURLcode result = Curl_pp_sendf(&conn->proto.pop3c.pp, "%s", "STLS");
if(!result)
state(conn, POP3_STARTTLS);
*/
static CURLcode pop3_perform_upgrade_tls(struct connectdata *conn)
{
- CURLcode result = CURLE_OK;
- struct pop3_conn *pop3c = &conn->proto.pop3c;
-
/* Start the SSL connection */
- result = Curl_ssl_connect_nonblocking(conn, FIRSTSOCKET, &pop3c->ssldone);
+ struct pop3_conn *pop3c = &conn->proto.pop3c;
+ CURLcode result = Curl_ssl_connect_nonblocking(conn, FIRSTSOCKET,
+ &pop3c->ssldone);
if(!result) {
if(pop3c->state != POP3_UPGRADETLS)
*/
static CURLcode pop3_perform_quit(struct connectdata *conn)
{
- CURLcode result = CURLE_OK;
-
/* Send the QUIT command */
- result = Curl_pp_sendf(&conn->proto.pop3c.pp, "%s", "QUIT");
+ CURLcode result = Curl_pp_sendf(&conn->proto.pop3c.pp, "%s", "QUIT");
if(!result)
state(conn, POP3_QUIT);
static CURLcode smb_parse_url_path(struct connectdata *conn)
{
- CURLcode result = CURLE_OK;
struct Curl_easy *data = conn->data;
struct smb_request *req = data->req.protop;
struct smb_conn *smbc = &conn->proto.smbc;
char *slash;
/* URL decode the path */
- result = Curl_urldecode(data, data->state.up.path, 0, &path, NULL, TRUE);
+ CURLcode result = Curl_urldecode(data, data->state.up.path, 0, &path, NULL,
+ TRUE);
if(result)
return result;
*/
static CURLcode smtp_perform_starttls(struct connectdata *conn)
{
- CURLcode result = CURLE_OK;
-
/* Send the STARTTLS command */
- result = Curl_pp_sendf(&conn->proto.smtpc.pp, "%s", "STARTTLS");
+ CURLcode result = Curl_pp_sendf(&conn->proto.smtpc.pp, "%s", "STARTTLS");
if(!result)
state(conn, SMTP_STARTTLS);
*/
static CURLcode smtp_perform_upgrade_tls(struct connectdata *conn)
{
- CURLcode result = CURLE_OK;
- struct smtp_conn *smtpc = &conn->proto.smtpc;
-
/* Start the SSL connection */
- result = Curl_ssl_connect_nonblocking(conn, FIRSTSOCKET, &smtpc->ssldone);
+ struct smtp_conn *smtpc = &conn->proto.smtpc;
+ CURLcode result = Curl_ssl_connect_nonblocking(conn, FIRSTSOCKET,
+ &smtpc->ssldone);
if(!result) {
if(smtpc->state != SMTP_UPGRADETLS)
*/
static CURLcode smtp_perform_quit(struct connectdata *conn)
{
- CURLcode result = CURLE_OK;
-
/* Send the QUIT command */
- result = Curl_pp_sendf(&conn->proto.smtpc.pp, "%s", "QUIT");
+ CURLcode result = Curl_pp_sendf(&conn->proto.smtpc.pp, "%s", "QUIT");
if(!result)
state(conn, SMTP_QUIT);
bool *done)
{
struct ssh_conn *sshc = &conn->proto.sshc;
- CURLcode result = CURLE_OK;
bool block; /* we store the status and use that to provide a ssh_getsock()
implementation */
+ CURLcode result = myssh_statemach_act(conn, &block);
- result = myssh_statemach_act(conn, &block);
*done = (sshc->state == SSH_STOP) ? TRUE : FALSE;
myssh_block2waitfor(conn, block);
const char *service,
char **outptr, size_t *outlen)
{
- CURLcode result = CURLE_OK;
size_t i;
MD5_context *ctxt;
char *response = NULL;
char *spn = NULL;
/* Decode the challenge message */
- result = auth_decode_digest_md5_message(chlg64, nonce, sizeof(nonce),
- realm, sizeof(realm),
- algorithm, sizeof(algorithm),
- qop_options, sizeof(qop_options));
+ CURLcode result = auth_decode_digest_md5_message(chlg64, nonce,
+ sizeof(nonce), realm,
+ sizeof(realm), algorithm,
+ sizeof(algorithm),
+ qop_options,
+ sizeof(qop_options));
if(result)
return result;
/* give application a chance to interfere with SSL set up. */
if(data->set.ssl.fsslctx) {
- CURLcode result = CURLE_OK;
- result = (*data->set.ssl.fsslctx)(data, BACKEND->ctx,
- data->set.ssl.fsslctxp);
+ CURLcode result = (*data->set.ssl.fsslctx)(data, BACKEND->ctx,
+ data->set.ssl.fsslctxp);
if(result) {
failf(data, "error signaled by ssl ctx callback");
return result;
ret = SSL_connect(BACKEND->handle);
if(ret != SSL_SUCCESS) {
- char error_buffer[MESALINK_MAX_ERROR_SZ];
int detail = SSL_get_error(BACKEND->handle, ret);
if(SSL_ERROR_WANT_CONNECT == detail || SSL_ERROR_WANT_READ == detail) {
return CURLE_OK;
}
else {
+ char error_buffer[MESALINK_MAX_ERROR_SZ];
failf(data,
"SSL_connect failed with error %d: %s",
detail,
va_list arg;
void *paramp;
CURLcode ret;
- unsigned int ccsid;
- char * * cpp;
struct Curl_easy * data;
- struct curl_slist * * slp;
- struct curl_certinfo * cipf;
- struct curl_certinfo * cipt;
/* WARNING: unlike curl_easy_getinfo(), the strings returned by this
procedure have to be free'ed. */
paramp = va_arg(arg, void *);
ret = Curl_getinfo(data, info, paramp);
- if(ret == CURLE_OK)
+ if(ret == CURLE_OK) {
+ unsigned int ccsid;
+ char **cpp;
+ struct curl_slist **slp;
+ struct curl_certinfo *cipf;
+ struct curl_certinfo *cipt;
+
switch((int) info & CURLINFO_TYPEMASK) {
case CURLINFO_STRING:
break;
}
}
+ }
va_end(arg);
return ret;
{
char *d = (char *) NULL;
- char *s;
if(header) {
header = dynconvert(ASCII_CCSID, header, -1, ccsidin);
if(header) {
- s = curl_pushheader_byname(h, header);
+ char *s = curl_pushheader_byname(h, header);
free((char *) header);
if(s)
int flags)
{
- char * enodename;
- char * eservname;
+ char *enodename = NULL;
+ char *eservname = NULL;
int status;
- int i;
-
- enodename = (char *) NULL;
- eservname = (char *) NULL;
if(nodename && nodenamelen) {
enodename = malloc(nodenamelen);
eservname, servnamelen, flags);
if(!status) {
+ int i;
if(enodename) {
i = QadrtConvertE2A(nodename, enodename,
nodenamelen - 1, strlen(enodename));
Curl_gss_convert_in_place(OM_uint32 * minor_status, gss_buffer_t buf)
{
- unsigned int i;
- char * t;
+ unsigned int i = buf->length;
/* Convert `buf' in place, from EBCDIC to ASCII.
If error, release the buffer and return -1. Else return 0. */
- i = buf->length;
-
if(i) {
- t = malloc(i);
+ char *t = malloc(i);
if(!t) {
gss_release_buffer(minor_status, buf);
{
int rc;
- unsigned int i;
gss_buffer_desc in;
gss_buffer_t inp;
if(inp) {
if(inp->length && inp->value) {
- i = inp->length;
+ unsigned int i = inp->length;
in.value = malloc(i + 1);
if(!in.value) {
if((sts & 1) && (iosb.iosb$w_status & 1))
buffer[iosb.iosb$w_bcnt] = '\0';
- sts = sys$dassgn(chan);
+ sys$dassgn(chan);
}
return buffer; /* we always return success */
}
{
pthread_t tid[NUM_THREADS];
int i;
- int error;
CURLSH *share;
struct initurl url[NUM_THREADS];
init_locks();
for(i = 0; i< NUM_THREADS; i++) {
+ int error;
url[i].url = URL;
url[i].share = share;
url[i].threadno = i;
/* 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);
}
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,
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",
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",
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++;
else
rc = CURLUE_OK;
if(!rc) {
+ char *url = NULL;
CURLUcode uc = updateurl(urlp, set_parts_list[i].set,
set_parts_list[i].setflags);
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;
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++;
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) {
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;
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;
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;
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) {
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();
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 */
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;
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;
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];
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) {