Unverified Commit c45360d4 authored by Marian Klymov's avatar Marian Klymov Committed by Daniel Stenberg
Browse files

cppcheck: fix warnings

- Get rid of variable that was generating false positive warning
(unitialized)

- Fix issues in tests

- Reduce scope of several variables all over

etc

Closes #2631
parent 38203f15
Loading
Loading
Loading
Loading
+1 −2
Original line number Original line Diff line number Diff line
@@ -49,13 +49,12 @@ static size_t decodeQuantum(unsigned char *dest, const char *src)
  unsigned long i, x = 0;
  unsigned long i, x = 0;


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

    if(*s == '=') {
    if(*s == '=') {
      x = (x << 6);
      x = (x << 6);
      padding++;
      padding++;
    }
    }
    else {
    else {
      unsigned long v = 0;
      p = base64;
      p = base64;


      while(*p && (*p != *s)) {
      while(*p && (*p != *s)) {
+1 −5
Original line number Original line Diff line number Diff line
@@ -1237,8 +1237,6 @@ static int conn_is_conn(struct connectdata *conn, void *param)
curl_socket_t Curl_getconnectinfo(struct Curl_easy *data,
curl_socket_t Curl_getconnectinfo(struct Curl_easy *data,
                                  struct connectdata **connp)
                                  struct connectdata **connp)
{
{
  curl_socket_t sockfd;

  DEBUGASSERT(data);
  DEBUGASSERT(data);


  /* this works for an easy handle:
  /* this works for an easy handle:
@@ -1264,12 +1262,10 @@ curl_socket_t Curl_getconnectinfo(struct Curl_easy *data,
    if(connp)
    if(connp)
      /* only store this if the caller cares for it */
      /* only store this if the caller cares for it */
      *connp = c;
      *connp = c;
    sockfd = c->sock[FIRSTSOCKET];
    return c->sock[FIRSTSOCKET];
  }
  }
  else
  else
    return CURL_SOCKET_BAD;
    return CURL_SOCKET_BAD;

  return sockfd;
}
}


/*
/*
+3 −5
Original line number Original line Diff line number Diff line
@@ -163,7 +163,6 @@ static CURLcode inflate_stream(struct connectdata *conn,
  z_stream *z = &zp->z;         /* zlib state structure */
  z_stream *z = &zp->z;         /* zlib state structure */
  uInt nread = z->avail_in;
  uInt nread = z->avail_in;
  Bytef *orig_in = z->next_in;
  Bytef *orig_in = z->next_in;
  int status;                   /* zlib status */
  bool done = FALSE;
  bool done = FALSE;
  CURLcode result = CURLE_OK;   /* Curl_client_write status */
  CURLcode result = CURLE_OK;   /* Curl_client_write status */
  char *decomp;                 /* Put the decompressed data here. */
  char *decomp;                 /* Put the decompressed data here. */
@@ -184,6 +183,7 @@ static CURLcode inflate_stream(struct connectdata *conn,
  /* because the buffer size is fixed, iteratively decompress and transfer to
  /* because the buffer size is fixed, iteratively decompress and transfer to
     the client via downstream_write function. */
     the client via downstream_write function. */
  while(!done) {
  while(!done) {
    int status;                   /* zlib status */
    done = TRUE;
    done = TRUE;


    /* (re)set buffer for decompressed output for every iteration */
    /* (re)set buffer for decompressed output for every iteration */
@@ -761,7 +761,6 @@ char *Curl_all_content_encodings(void)
  const content_encoding * const *cep;
  const content_encoding * const *cep;
  const content_encoding *ce;
  const content_encoding *ce;
  char *ace;
  char *ace;
  char *p;


  for(cep = encodings; *cep; cep++) {
  for(cep = encodings; *cep; cep++) {
    ce = *cep;
    ce = *cep;
@@ -774,7 +773,7 @@ char *Curl_all_content_encodings(void)


  ace = malloc(len);
  ace = malloc(len);
  if(ace) {
  if(ace) {
    p = ace;
    char *p = ace;
    for(cep = encodings; *cep; cep++) {
    for(cep = encodings; *cep; cep++) {
      ce = *cep;
      ce = *cep;
      if(!strcasecompare(ce->name, CONTENT_ENCODING_DEFAULT)) {
      if(!strcasecompare(ce->name, CONTENT_ENCODING_DEFAULT)) {
@@ -921,10 +920,9 @@ void Curl_unencode_cleanup(struct connectdata *conn)
static const content_encoding *find_encoding(const char *name, size_t len)
static const content_encoding *find_encoding(const char *name, size_t len)
{
{
  const content_encoding * const *cep;
  const content_encoding * const *cep;
  const content_encoding *ce;


  for(cep = encodings; *cep; cep++) {
  for(cep = encodings; *cep; cep++) {
    ce = *cep;
    const content_encoding *ce = *cep;
    if((strncasecompare(name, ce->name, len) && !ce->name[len]) ||
    if((strncasecompare(name, ce->name, len) && !ce->name[len]) ||
       (ce->alias && strncasecompare(name, ce->alias, len) && !ce->alias[len]))
       (ce->alias && strncasecompare(name, ce->alias, len) && !ce->alias[len]))
      return ce;
      return ce;
+3 −4
Original line number Original line Diff line number Diff line
@@ -376,13 +376,13 @@ static void strstore(char **str, const char *newstr)
 */
 */
static void remove_expired(struct CookieInfo *cookies)
static void remove_expired(struct CookieInfo *cookies)
{
{
  struct Cookie *co, *nx, *pv;
  struct Cookie *co, *nx;
  curl_off_t now = (curl_off_t)time(NULL);
  curl_off_t now = (curl_off_t)time(NULL);
  unsigned int i;
  unsigned int i;


  for(i = 0; i < COOKIE_HASH_SIZE; i++) {
  for(i = 0; i < COOKIE_HASH_SIZE; i++) {
    struct Cookie *pv = NULL;
    co = cookies->cookies[i];
    co = cookies->cookies[i];
    pv = NULL;
    while(co) {
    while(co) {
      nx = co->next;
      nx = co->next;
      if(co->expires && co->expires < now) {
      if(co->expires && co->expires < now) {
@@ -1385,9 +1385,8 @@ void Curl_cookie_clearsess(struct CookieInfo *cookies)
 ****************************************************************************/
 ****************************************************************************/
void Curl_cookie_cleanup(struct CookieInfo *c)
void Curl_cookie_cleanup(struct CookieInfo *c)
{
{
  unsigned int i;

  if(c) {
  if(c) {
    unsigned int i;
    free(c->filename);
    free(c->filename);
    for(i = 0; i < COOKIE_HASH_SIZE; i++)
    for(i = 0; i < COOKIE_HASH_SIZE; i++)
      Curl_cookie_freelist(c->cookies[i]);
      Curl_cookie_freelist(c->cookies[i]);
+1 −2
Original line number Original line Diff line number Diff line
@@ -146,7 +146,6 @@ CURLcode Curl_sasl_parse_url_auth_option(struct SASL *sasl,
                                         const char *value, size_t len)
                                         const char *value, size_t len)
{
{
  CURLcode result = CURLE_OK;
  CURLcode result = CURLE_OK;
  unsigned int mechbit;
  size_t mechlen;
  size_t mechlen;


  if(!len)
  if(!len)
@@ -160,7 +159,7 @@ CURLcode Curl_sasl_parse_url_auth_option(struct SASL *sasl,
  if(!strncmp(value, "*", len))
  if(!strncmp(value, "*", len))
    sasl->prefmech = SASL_AUTH_DEFAULT;
    sasl->prefmech = SASL_AUTH_DEFAULT;
  else {
  else {
    mechbit = Curl_sasl_decode_mech(value, len, &mechlen);
    unsigned int mechbit = Curl_sasl_decode_mech(value, len, &mechlen);
    if(mechbit && mechlen == len)
    if(mechbit && mechlen == len)
      sasl->prefmech |= mechbit;
      sasl->prefmech |= mechbit;
    else
    else
Loading