]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
checksrc: find bad indentation in conditions without open brace
authorDaniel Stenberg <daniel@haxx.se>
Fri, 28 Apr 2023 16:07:33 +0000 (18:07 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 28 Apr 2023 21:11:00 +0000 (23:11 +0200)
If the previous line starts with if/while/for AND ends with a closed
parenthesis and there's an equal number of open and closed parentheses
on that line, verify that this line is indented $indent more steps, if
not a cpp line.

Also adjust the fall-out from this fix.

Closes #11054

17 files changed:
lib/cf-socket.c
lib/ftp.c
lib/imap.c
lib/inet_ntop.c
lib/ldap.c
lib/mime.c
lib/multi.c
lib/openldap.c
lib/pop3.c
lib/vquic/curl_msh3.c
lib/vquic/curl_ngtcp2.c
lib/vtls/sectransp.c
scripts/checksrc.pl
src/tool_getparam.c
src/tool_operate.c
tests/libtest/lib678.c
tests/server/socksd.c

index 331d2c9c9c6df3a77d313d38d4f9014289ef93bb..0ad918bef98100d84a4e4710e2f96d2ec7015dd8 100644 (file)
@@ -241,7 +241,7 @@ void Curl_sock_assign_addr(struct Curl_sockaddr_ex *dest,
   dest->addrlen = ai->ai_addrlen;
 
   if(dest->addrlen > sizeof(struct Curl_sockaddr_storage))
-     dest->addrlen = sizeof(struct Curl_sockaddr_storage);
+    dest->addrlen = sizeof(struct Curl_sockaddr_storage);
   memcpy(&dest->sa_addr, ai->ai_addr, dest->addrlen);
 }
 
@@ -1222,7 +1222,7 @@ static bool cf_socket_data_pending(struct Curl_cfilter *cf,
 
   (void)data;
   if(!Curl_bufq_is_empty(&ctx->recvbuf))
-     return TRUE;
+    return TRUE;
 
   readable = SOCKET_READABLE(ctx->sock, 0);
   return (readable > 0 && (readable & CURL_CSELECT_IN));
index c868c2b6e4e6e3f54fc0e97cd4aef8ac1a1e4860..e492efc8a25aa3c39a50d3a9db87fc1c6a91fff8 100644 (file)
--- a/lib/ftp.c
+++ b/lib/ftp.c
@@ -4134,7 +4134,7 @@ CURLcode ftp_parse_url_path(struct Curl_easy *data)
     case FTPFILE_NOCWD: /* fastest, but less standard-compliant */
 
       if((pathLen > 0) && (rawPath[pathLen - 1] != '/'))
-          fileName = rawPath;  /* this is a full file path */
+        fileName = rawPath;  /* this is a full file path */
       /*
         else: ftpc->file is not used anywhere other than for operations on
               a file. In other words, never for directory operations.
index 1952e66a1efcdb93b5927d342560f28057d65f51..ed197c9316b2246f663ecf63bf08082cc67ad255 100644 (file)
@@ -1931,7 +1931,7 @@ static CURLcode imap_parse_url_options(struct connectdata *conn)
     const char *value;
 
     while(*ptr && *ptr != '=')
-        ptr++;
+      ptr++;
 
     value = ptr + 1;
 
index 770ed3a59b241c0f29fc193d119dd9269b6abab2..fa9077376b700773048eeba9f91e30e64a1eaf3e 100644 (file)
@@ -164,7 +164,7 @@ static char *inet_ntop6 (const unsigned char *src, char *dst, size_t size)
   /* Was it a trailing run of 0x00's?
    */
   if(best.base != -1 && (best.base + best.len) == (IN6ADDRSZ / INT16SZ))
-     *tp++ = ':';
+    *tp++ = ':';
   *tp++ = '\0';
 
   /* Check for overflow, copy, and we're done.
index 595e4b3b3bda1faf5a7a4856a9a5f5de43e57980..4c88b0aaeb70f9fcf1dd32780fceefa4799be0f5 100644 (file)
@@ -731,7 +731,7 @@ static CURLcode ldap_do(struct Curl_easy *data, bool *done)
     }
 
     if(ber)
-       ber_free(ber, 0);
+      ber_free(ber, 0);
   }
 
 quit:
@@ -1069,7 +1069,7 @@ static int _ldap_url_parse(struct Curl_easy *data,
 
   *ludpp = NULL;
   if(!ludp)
-     return LDAP_NO_MEMORY;
+    return LDAP_NO_MEMORY;
 
   rc = _ldap_url_parse2(data, conn, ludp);
   if(rc != LDAP_SUCCESS) {
index 0b21a1027e0b7a6f27f41cbb6d6c68115688d241..39aac8f2418b63b081c5202266bcd2e1ab4a8fc3 100644 (file)
@@ -1107,7 +1107,7 @@ static int mime_subparts_seek(void *instream, curl_off_t offset, int whence)
     return CURL_SEEKFUNC_CANTSEEK;    /* Only support full rewind. */
 
   if(mime->state.state == MIMESTATE_BEGIN)
-   return CURL_SEEKFUNC_OK;           /* Already rewound. */
+    return CURL_SEEKFUNC_OK;           /* Already rewound. */
 
   for(part = mime->firstpart; part; part = part->nextpart) {
     int res = mime_part_rewind(part);
@@ -1734,7 +1734,7 @@ const char *Curl_mime_contenttype(const char *filename)
       size_t len2 = strlen(ctts[i].extension);
 
       if(len1 >= len2 && strcasecompare(nameend - len2, ctts[i].extension))
-          return ctts[i].type;
+        return ctts[i].type;
     }
   }
   return NULL;
index 5fcb20fa61fce5cc79e816384b6ec9dbe1281310..4ee51a1533a63d4f6e515473f3f170d4ad633333 100644 (file)
@@ -2021,7 +2021,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
       else
 #endif
         if(conn->bits.conn_to_host)
-        hostname = conn->conn_to_host.name;
+          hostname = conn->conn_to_host.name;
       else
         hostname = conn->host.name;
 
index b9feeda0589c99e01533bd66e73a344230517c92..41fecf9143c5ecb3f469066870c65e51a4a3f2dd 100644 (file)
@@ -295,7 +295,7 @@ static CURLcode oldap_parse_login_options(struct connectdata *conn)
     const char *value;
 
     while(*ptr && *ptr != '=')
-        ptr++;
+      ptr++;
 
     value = ptr + 1;
 
index 36707e5352494bf3754053fc3f3f5d9fe24bb84e..0de34cc1139e9300e7d92cf3cf78f6a4ed1a4f03 100644 (file)
@@ -1376,7 +1376,7 @@ static CURLcode pop3_parse_url_options(struct connectdata *conn)
     const char *value;
 
     while(*ptr && *ptr != '=')
-        ptr++;
+      ptr++;
 
     value = ptr + 1;
 
index 438a60d4714fefde6cc18490333254819773566b..40e89379fc4028380040df1179a14edf930cbe5e 100644 (file)
@@ -542,7 +542,7 @@ static ssize_t cf_msh3_recv(struct Curl_cfilter *cf, struct Curl_easy *data,
     if(nread < 0)
       goto out;
     if(stream->closed)
-       drain_stream(cf, data);
+      drain_stream(cf, data);
   }
   else if(stream->closed) {
     nread = recv_closed_stream(cf, data, err);
index c76c674444c741fd35e621ddaacf53e5bf6f99c0..1ca1227b042a503124367ece1a6ca8fc651c0079 100644 (file)
@@ -1710,7 +1710,7 @@ static CURLcode qng_verify_peer(struct Curl_cfilter *cf,
   Curl_conn_get_host(data, cf->sockindex, &hostname, &disp_hostname, &port);
   snihost = Curl_ssl_snihost(data, hostname, NULL);
   if(!snihost)
-      return CURLE_PEER_FAILED_VERIFICATION;
+    return CURLE_PEER_FAILED_VERIFICATION;
 
   cf->conn->bits.multiplex = TRUE; /* at least potentially multiplexed */
   cf->conn->httpversion = 30;
index 618c0c5865a57b483095f75fcf59d898f6ab12e3..175b7a96da9f5a9459d93ae23b924a512986acc4 100644 (file)
@@ -1548,7 +1548,7 @@ static CURLcode sectransp_set_selected_ciphers(struct Curl_easy *data,
 
     /* Skip separators */
     while(is_separator(*cipher_start))
-       cipher_start++;
+      cipher_start++;
     if(*cipher_start == '\0') {
       break;
     }
index 540b22978fa59884e53c5d14c0a2b8e51fd874fc..1ec9212a0f079d75dff960f0cda7378b365748f2 100755 (executable)
@@ -765,6 +765,32 @@ sub scanfile {
             }
         }
 
+        # if the previous line starts with if/while/for AND ends with a closed
+        # parenthesis and there's an equal number of open and closed
+        # parentheses, check that this line is indented $indent more steps, if
+        # not a cpp line
+        elsif(!$prevp && ($prevl =~ /^( *)(if|while|for)(\(.*\))\z/)) {
+            my $first = length($1);
+            my $op = $3;
+            my $cl = $3;
+
+            $op =~ s/[^(]//g;
+            $cl =~ s/[^)]//g;
+
+            if(length($op) == length($cl)) {
+                # this line has some character besides spaces
+                if($l =~ /^( *)[^ ]/) {
+                    my $second = length($1);
+                    my $expect = $first+$indent;
+                    if($expect != $second) {
+                        my $diff = $second - $first;
+                        checkwarn("INDENTATION", $line, length($1), $file, $ol,
+                                  "not indented $indent steps (uses $diff)");
+                    }
+                }
+            }
+        }
+
         # check for 'char * name'
         if(($l =~ /(^.*(char|int|long|void|CURL|CURLM|CURLMsg|[cC]url_[A-Za-z_]+|struct [a-zA-Z_]+) *(\*+)) (\w+)/) && ($4 !~ /^(const|volatile)$/)) {
             checkwarn("ASTERISKSPACE",
index b33e60300a0907bb815be06fea4e837015cc3a72..c9810e9d40c7e6c80d5c29decf19dc882c5b1199 100644 (file)
@@ -884,7 +884,7 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */
         ParameterError pe = GetSizeParameter(global, nextarg, "rate", &value);
 
         if(pe != PARAM_OK)
-           return pe;
+          return pe;
         config->recvpersecond = value;
         config->sendpersecond = value;
       }
@@ -1060,7 +1060,7 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */
             GetSizeParameter(global, nextarg, "max-filesize", &value);
 
           if(pe != PARAM_OK)
-             return pe;
+            return pe;
           config->max_filesize = value;
         }
         break;
index 72b0253306ae27427196199a1e1a432fdbe63efa..06ae39396cc0b4f542fca60201658b33c646d253 100644 (file)
@@ -1878,7 +1878,7 @@ static CURLcode single_transfer(struct GlobalConfig *global,
         if(config->dns_ipv4_addr)
           my_setopt_str(curl, CURLOPT_DNS_LOCAL_IP4, config->dns_ipv4_addr);
         if(config->dns_ipv6_addr)
-        my_setopt_str(curl, CURLOPT_DNS_LOCAL_IP6, config->dns_ipv6_addr);
+          my_setopt_str(curl, CURLOPT_DNS_LOCAL_IP6, config->dns_ipv6_addr);
 
         /* new in libcurl 7.6.2: */
         my_setopt_slist(curl, CURLOPT_TELNETOPTIONS, config->telnet_options);
index 8da39111d99b6ef8a12b0299b2857a3c1d3d7d84..942808e2a6c820b686317b51442ab7ca392af39d 100644 (file)
@@ -44,12 +44,12 @@ static int loadfile(const char *filename, void **filedata, size_t *filesize)
       else
         datasize = (size_t)cert_tell;
       if(continue_reading)
-         continue_reading = fseek(fInCert, 0, SEEK_SET) == 0;
+        continue_reading = fseek(fInCert, 0, SEEK_SET) == 0;
       if(continue_reading)
-          data = malloc(datasize + 1);
+        data = malloc(datasize + 1);
       if((!data) ||
-          ((int)fread(data, datasize, 1, fInCert) != 1))
-          continue_reading = FALSE;
+         ((int)fread(data, datasize, 1, fInCert) != 1))
+        continue_reading = FALSE;
       fclose(fInCert);
       if(!continue_reading) {
         free(data);
index 071b4d25d88057fd2cc70a27897988365c883fd3..22a5ee7f5ba54566075f947c543fbd5397354e3b 100644 (file)
@@ -1095,7 +1095,7 @@ int main(int argc, char *argv[])
 
 #ifdef USE_UNIX_SOCKETS
   if(socket_domain == AF_UNIX)
-      logmsg("Listening on unix socket %s", unix_socket);
+    logmsg("Listening on unix socket %s", unix_socket);
   else
 #endif
   logmsg("Listening on port %hu", port);