summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2023-04-28 18:07:33 +0200
committerDaniel Stenberg <daniel@haxx.se>2023-04-28 23:11:00 +0200
commit9ce7eee07042605045dcfd02a6f5b38ad5c8a05d (patch)
tree7a83474325c43f8d34233dae5bad509b2475ce74
parent31303c34e90949847860db82c4768cab1482beda (diff)
downloadcurl-9ce7eee07042605045dcfd02a6f5b38ad5c8a05d.tar.gz
checksrc: find bad indentation in conditions without open brace
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
-rw-r--r--lib/cf-socket.c4
-rw-r--r--lib/ftp.c2
-rw-r--r--lib/imap.c2
-rw-r--r--lib/inet_ntop.c2
-rw-r--r--lib/ldap.c4
-rw-r--r--lib/mime.c4
-rw-r--r--lib/multi.c2
-rw-r--r--lib/openldap.c2
-rw-r--r--lib/pop3.c2
-rw-r--r--lib/vquic/curl_msh3.c2
-rw-r--r--lib/vquic/curl_ngtcp2.c2
-rw-r--r--lib/vtls/sectransp.c2
-rwxr-xr-xscripts/checksrc.pl26
-rw-r--r--src/tool_getparam.c4
-rw-r--r--src/tool_operate.c2
-rw-r--r--tests/libtest/lib678.c8
-rw-r--r--tests/server/socksd.c2
17 files changed, 49 insertions, 23 deletions
diff --git a/lib/cf-socket.c b/lib/cf-socket.c
index 331d2c9c9..0ad918bef 100644
--- a/lib/cf-socket.c
+++ b/lib/cf-socket.c
@@ -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));
diff --git a/lib/ftp.c b/lib/ftp.c
index c868c2b6e..e492efc8a 100644
--- 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.
diff --git a/lib/imap.c b/lib/imap.c
index 1952e66a1..ed197c931 100644
--- a/lib/imap.c
+++ b/lib/imap.c
@@ -1931,7 +1931,7 @@ static CURLcode imap_parse_url_options(struct connectdata *conn)
const char *value;
while(*ptr && *ptr != '=')
- ptr++;
+ ptr++;
value = ptr + 1;
diff --git a/lib/inet_ntop.c b/lib/inet_ntop.c
index 770ed3a59..fa9077376 100644
--- a/lib/inet_ntop.c
+++ b/lib/inet_ntop.c
@@ -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.
diff --git a/lib/ldap.c b/lib/ldap.c
index 595e4b3b3..4c88b0aae 100644
--- a/lib/ldap.c
+++ b/lib/ldap.c
@@ -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) {
diff --git a/lib/mime.c b/lib/mime.c
index 0b21a1027..39aac8f24 100644
--- a/lib/mime.c
+++ b/lib/mime.c
@@ -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;
diff --git a/lib/multi.c b/lib/multi.c
index 5fcb20fa6..4ee51a153 100644
--- a/lib/multi.c
+++ b/lib/multi.c
@@ -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;
diff --git a/lib/openldap.c b/lib/openldap.c
index b9feeda05..41fecf914 100644
--- a/lib/openldap.c
+++ b/lib/openldap.c
@@ -295,7 +295,7 @@ static CURLcode oldap_parse_login_options(struct connectdata *conn)
const char *value;
while(*ptr && *ptr != '=')
- ptr++;
+ ptr++;
value = ptr + 1;
diff --git a/lib/pop3.c b/lib/pop3.c
index 36707e535..0de34cc11 100644
--- a/lib/pop3.c
+++ b/lib/pop3.c
@@ -1376,7 +1376,7 @@ static CURLcode pop3_parse_url_options(struct connectdata *conn)
const char *value;
while(*ptr && *ptr != '=')
- ptr++;
+ ptr++;
value = ptr + 1;
diff --git a/lib/vquic/curl_msh3.c b/lib/vquic/curl_msh3.c
index 438a60d47..40e89379f 100644
--- a/lib/vquic/curl_msh3.c
+++ b/lib/vquic/curl_msh3.c
@@ -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);
diff --git a/lib/vquic/curl_ngtcp2.c b/lib/vquic/curl_ngtcp2.c
index c76c67444..1ca1227b0 100644
--- a/lib/vquic/curl_ngtcp2.c
+++ b/lib/vquic/curl_ngtcp2.c
@@ -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;
diff --git a/lib/vtls/sectransp.c b/lib/vtls/sectransp.c
index 618c0c586..175b7a96d 100644
--- a/lib/vtls/sectransp.c
+++ b/lib/vtls/sectransp.c
@@ -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;
}
diff --git a/scripts/checksrc.pl b/scripts/checksrc.pl
index 540b22978..1ec9212a0 100755
--- a/scripts/checksrc.pl
+++ b/scripts/checksrc.pl
@@ -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",
diff --git a/src/tool_getparam.c b/src/tool_getparam.c
index b33e60300..c9810e9d4 100644
--- a/src/tool_getparam.c
+++ b/src/tool_getparam.c
@@ -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;
diff --git a/src/tool_operate.c b/src/tool_operate.c
index 72b025330..06ae39396 100644
--- a/src/tool_operate.c
+++ b/src/tool_operate.c
@@ -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);
diff --git a/tests/libtest/lib678.c b/tests/libtest/lib678.c
index 8da39111d..942808e2a 100644
--- a/tests/libtest/lib678.c
+++ b/tests/libtest/lib678.c
@@ -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);
diff --git a/tests/server/socksd.c b/tests/server/socksd.c
index 071b4d25d..22a5ee7f5 100644
--- a/tests/server/socksd.c
+++ b/tests/server/socksd.c
@@ -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);