Skip to content

Commit

Permalink
cleanups: reduce variable scope
Browse files Browse the repository at this point in the history
cppcheck pointed these out.
  • Loading branch information
bagder committed Oct 14, 2014
1 parent c2d5f2e commit 628290b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
7 changes: 3 additions & 4 deletions lib/base64.c
Expand Up @@ -49,10 +49,10 @@ static size_t decodeQuantum(unsigned char *dest, const char *src)
{
size_t padding = 0;
const char *s, *p;
unsigned long i, v, x = 0;
unsigned long i, x = 0;

for(i = 0, s = src; i < 4; i++, s++) {
v = 0;
unsigned long v = 0;

if(*s == '=') {
x = (x << 6);
Expand Down Expand Up @@ -107,7 +107,6 @@ CURLcode Curl_base64_decode(const char *src,
size_t length = 0;
size_t padding = 0;
size_t i;
size_t result;
size_t numQuantums;
size_t rawlen = 0;
unsigned char *pos;
Expand Down Expand Up @@ -151,7 +150,7 @@ CURLcode Curl_base64_decode(const char *src,

/* Decode the quantums */
for(i = 0; i < numQuantums; i++) {
result = decodeQuantum(pos, src);
size_t result = decodeQuantum(pos, src);
if(!result) {
Curl_safefree(newstr);

Expand Down
5 changes: 2 additions & 3 deletions lib/conncache.c
Expand Up @@ -199,7 +199,6 @@ void Curl_conncache_foreach(struct conncache *connc,
he = Curl_hash_next_element(&iter);
while(he) {
struct connectbundle *bundle;
struct connectdata *conn;

bundle = he->ptr;
he = Curl_hash_next_element(&iter);
Expand All @@ -208,7 +207,7 @@ void Curl_conncache_foreach(struct conncache *connc,
while(curr) {
/* Yes, we need to update curr before calling func(), because func()
might decide to remove the connection */
conn = curr->ptr;
struct connectdata *conn = curr->ptr;
curr = curr->next;

if(1 == func(conn, param))
Expand All @@ -223,14 +222,14 @@ struct connectdata *
Curl_conncache_find_first_connection(struct conncache *connc)
{
struct curl_hash_iterator iter;
struct curl_llist_element *curr;
struct curl_hash_element *he;
struct connectbundle *bundle;

Curl_hash_start_iterate(connc->hash, &iter);

he = Curl_hash_next_element(&iter);
while(he) {
struct curl_llist_element *curr;
bundle = he->ptr;

curr = bundle->conn_list->head;
Expand Down
17 changes: 9 additions & 8 deletions lib/connect.c
Expand Up @@ -257,12 +257,6 @@ static CURLcode bindlocal(struct connectdata *conn,
int portnum = data->set.localportrange;
const char *dev = data->set.str[STRING_DEVICE];
int error;
char myhost[256] = "";
int done = 0; /* -1 for error, 1 for address found */
bool is_interface = FALSE;
bool is_host = FALSE;
static const char *if_prefix = "if!";
static const char *host_prefix = "host!";

/*************************************************************
* Select device to bind socket to
Expand All @@ -274,6 +268,13 @@ static CURLcode bindlocal(struct connectdata *conn,
memset(&sa, 0, sizeof(struct Curl_sockaddr_storage));

if(dev && (strlen(dev)<255) ) {
char myhost[256] = "";
int done = 0; /* -1 for error, 1 for address found */
bool is_interface = FALSE;
bool is_host = FALSE;
static const char *if_prefix = "if!";
static const char *host_prefix = "host!";

if(strncmp(if_prefix, dev, strlen(if_prefix)) == 0) {
dev += strlen(if_prefix);
is_interface = TRUE;
Expand Down Expand Up @@ -656,7 +657,6 @@ static bool getaddressinfo(struct sockaddr* sa, char* addr,
connection */
void Curl_updateconninfo(struct connectdata *conn, curl_socket_t sockfd)
{
int error;
curl_socklen_t len;
struct Curl_sockaddr_storage ssrem;
struct Curl_sockaddr_storage ssloc;
Expand All @@ -667,6 +667,7 @@ void Curl_updateconninfo(struct connectdata *conn, curl_socket_t sockfd)
return;

if(!conn->bits.reuse) {
int error;

len = sizeof(struct Curl_sockaddr_storage);
if(getpeername(sockfd, (struct sockaddr*) &ssrem, &len)) {
Expand Down Expand Up @@ -813,10 +814,10 @@ CURLcode Curl_is_connected(struct connectdata *conn,
* address" for the given host. But first remember the latest error.
*/
if(error) {
char ipaddress[MAX_IPADR_LEN];
data->state.os_errno = error;
SET_SOCKERRNO(error);
if(conn->tempaddr[i]) {
char ipaddress[MAX_IPADR_LEN];
Curl_printable_address(conn->tempaddr[i], ipaddress, MAX_IPADR_LEN);
infof(data, "connect to %s port %ld failed: %s\n",
ipaddress, conn->port, Curl_strerror(conn, error));
Expand Down

0 comments on commit 628290b

Please sign in to comment.