Unverified Commit 10db3ef2 authored by Marcel Raad's avatar Marcel Raad
Browse files

lib: reduce variable scopes

Fixes Codacy/CppCheck warnings.

Closes https://github.com/curl/curl/pull/3872
parent 27af2ec2
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -628,7 +628,6 @@ UNITTEST bool getaddressinfo(struct sockaddr *sa, char *addr,
UNITTEST bool getaddressinfo(struct sockaddr *sa, char *addr,
                             long *port)
{
  unsigned short us_port;
  struct sockaddr_in *si = NULL;
#ifdef ENABLE_IPV6
  struct sockaddr_in6 *si6 = NULL;
@@ -642,7 +641,7 @@ UNITTEST bool getaddressinfo(struct sockaddr *sa, char *addr,
      si = (struct sockaddr_in *)(void *) sa;
      if(Curl_inet_ntop(sa->sa_family, &si->sin_addr,
                        addr, MAX_IPADR_LEN)) {
        us_port = ntohs(si->sin_port);
        unsigned short us_port = ntohs(si->sin_port);
        *port = us_port;
        return TRUE;
      }
@@ -652,7 +651,7 @@ UNITTEST bool getaddressinfo(struct sockaddr *sa, char *addr,
      si6 = (struct sockaddr_in6 *)(void *) sa;
      if(Curl_inet_ntop(sa->sa_family, &si6->sin6_addr,
                        addr, MAX_IPADR_LEN)) {
        us_port = ntohs(si6->sin6_port);
        unsigned short us_port = ntohs(si6->sin6_port);
        *port = us_port;
        return TRUE;
      }
+5 −5
Original line number Diff line number Diff line
@@ -1509,10 +1509,6 @@ static int cookie_output(struct CookieInfo *c, const char *dumphere)
  struct Cookie *co;
  FILE *out;
  bool use_stdout = FALSE;
  char *format_ptr;
  unsigned int i;
  unsigned int j;
  struct Cookie **array;

  if(!c)
    /* no cookie engine alive */
@@ -1539,6 +1535,10 @@ static int cookie_output(struct CookieInfo *c, const char *dumphere)
        out);

  if(c->numcookies) {
    unsigned int i;
    unsigned int j;
    struct Cookie **array;

    array = malloc(sizeof(struct Cookie *) * c->numcookies);
    if(!array) {
      if(!use_stdout)
@@ -1558,7 +1558,7 @@ static int cookie_output(struct CookieInfo *c, const char *dumphere)
    qsort(array, c->numcookies, sizeof(struct Cookie *), cookie_sort_ct);

    for(i = 0; i < j; i++) {
      format_ptr = get_netscape_format(array[i]);
      char *format_ptr = get_netscape_format(array[i]);
      if(format_ptr == NULL) {
        fprintf(out, "#\n# Fatal libcurl error\n");
        free(array);
+4 −3
Original line number Diff line number Diff line
@@ -584,7 +584,6 @@ UNITTEST DOHcode doh_decode(unsigned char *doh,
  unsigned short qdcount;
  unsigned short ancount;
  unsigned short type = 0;
  unsigned short class;
  unsigned short rdlength;
  unsigned short nscount;
  unsigned short arcount;
@@ -612,6 +611,7 @@ UNITTEST DOHcode doh_decode(unsigned char *doh,

  ancount = get16bit(doh, 6);
  while(ancount) {
    unsigned short class;
    unsigned int ttl;

    rc = skipqname(doh, dohlen, &index);
@@ -896,8 +896,6 @@ CURLcode Curl_doh_is_resolved(struct connectdata *conn,
    DOHcode rc;
    DOHcode rc2;
    struct dohentry de;
    struct Curl_dns_entry *dns;
    struct Curl_addrinfo *ai;
    /* remove DOH handles from multi handle and close them */
    curl_multi_remove_handle(data->multi, data->req.doh.probe[0].easy);
    Curl_close(data->req.doh.probe[0].easy);
@@ -927,6 +925,9 @@ CURLcode Curl_doh_is_resolved(struct connectdata *conn,
            data->req.doh.host);
    }
    if(!rc || !rc2) {
      struct Curl_dns_entry *dns;
      struct Curl_addrinfo *ai;

      infof(data, "DOH Host name: %s\n", data->req.doh.host);
      showdoh(data, &de);

+2 −4
Original line number Diff line number Diff line
@@ -127,16 +127,14 @@ static int hostmatch(char *hostname, char *pattern)

int Curl_cert_hostcheck(const char *match_pattern, const char *hostname)
{
  char *matchp;
  char *hostp;
  int res = 0;
  if(!match_pattern || !*match_pattern ||
      !hostname || !*hostname) /* sanity check */
    ;
  else {
    matchp = strdup(match_pattern);
    char *matchp = strdup(match_pattern);
    if(matchp) {
      hostp = strdup(hostname);
      char *hostp = strdup(hostname);
      if(hostp) {
        if(hostmatch(hostp, matchp) == CURL_HOST_MATCH)
          res = 1;
+3 −2
Original line number Diff line number Diff line
@@ -102,16 +102,17 @@ static void dump_addrinfo(struct connectdata *conn, const Curl_addrinfo *ai)
  printf("dump_addrinfo:\n");
  for(; ai; ai = ai->ai_next) {
    char buf[INET6_ADDRSTRLEN];
    char buffer[STRERROR_LEN];
    printf("    fam %2d, CNAME %s, ",
           ai->ai_family, ai->ai_canonname ? ai->ai_canonname : "<none>");
    if(Curl_printable_address(ai, buf, sizeof(buf)))
      printf("%s\n", buf);
    else
    else {
      char buffer[STRERROR_LEN];
      printf("failed; %s\n",
             Curl_strerror(SOCKERRNO, buffer, sizeof(buffer)));
    }
  }
}
#else
#define dump_addrinfo(x,y) Curl_nop_stmt
#endif
Loading