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
This commit is contained in:
Daniel Stenberg 2023-04-28 18:07:33 +02:00
Родитель 31303c34e9
Коммит 9ce7eee070
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 5CC908FDB71E12C2
17 изменённых файлов: 49 добавлений и 23 удалений

Просмотреть файл

@ -241,7 +241,7 @@ void Curl_sock_assign_addr(struct Curl_sockaddr_ex *dest,
dest->addrlen = ai->ai_addrlen; dest->addrlen = ai->ai_addrlen;
if(dest->addrlen > sizeof(struct Curl_sockaddr_storage)) 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); 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; (void)data;
if(!Curl_bufq_is_empty(&ctx->recvbuf)) if(!Curl_bufq_is_empty(&ctx->recvbuf))
return TRUE; return TRUE;
readable = SOCKET_READABLE(ctx->sock, 0); readable = SOCKET_READABLE(ctx->sock, 0);
return (readable > 0 && (readable & CURL_CSELECT_IN)); return (readable > 0 && (readable & CURL_CSELECT_IN));

Просмотреть файл

@ -4134,7 +4134,7 @@ CURLcode ftp_parse_url_path(struct Curl_easy *data)
case FTPFILE_NOCWD: /* fastest, but less standard-compliant */ case FTPFILE_NOCWD: /* fastest, but less standard-compliant */
if((pathLen > 0) && (rawPath[pathLen - 1] != '/')) 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 else: ftpc->file is not used anywhere other than for operations on
a file. In other words, never for directory operations. a file. In other words, never for directory operations.

Просмотреть файл

@ -1931,7 +1931,7 @@ static CURLcode imap_parse_url_options(struct connectdata *conn)
const char *value; const char *value;
while(*ptr && *ptr != '=') while(*ptr && *ptr != '=')
ptr++; ptr++;
value = ptr + 1; value = ptr + 1;

Просмотреть файл

@ -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? /* Was it a trailing run of 0x00's?
*/ */
if(best.base != -1 && (best.base + best.len) == (IN6ADDRSZ / INT16SZ)) if(best.base != -1 && (best.base + best.len) == (IN6ADDRSZ / INT16SZ))
*tp++ = ':'; *tp++ = ':';
*tp++ = '\0'; *tp++ = '\0';
/* Check for overflow, copy, and we're done. /* Check for overflow, copy, and we're done.

Просмотреть файл

@ -731,7 +731,7 @@ static CURLcode ldap_do(struct Curl_easy *data, bool *done)
} }
if(ber) if(ber)
ber_free(ber, 0); ber_free(ber, 0);
} }
quit: quit:
@ -1069,7 +1069,7 @@ static int _ldap_url_parse(struct Curl_easy *data,
*ludpp = NULL; *ludpp = NULL;
if(!ludp) if(!ludp)
return LDAP_NO_MEMORY; return LDAP_NO_MEMORY;
rc = _ldap_url_parse2(data, conn, ludp); rc = _ldap_url_parse2(data, conn, ludp);
if(rc != LDAP_SUCCESS) { if(rc != LDAP_SUCCESS) {

Просмотреть файл

@ -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. */ return CURL_SEEKFUNC_CANTSEEK; /* Only support full rewind. */
if(mime->state.state == MIMESTATE_BEGIN) 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) { for(part = mime->firstpart; part; part = part->nextpart) {
int res = mime_part_rewind(part); 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); size_t len2 = strlen(ctts[i].extension);
if(len1 >= len2 && strcasecompare(nameend - len2, ctts[i].extension)) if(len1 >= len2 && strcasecompare(nameend - len2, ctts[i].extension))
return ctts[i].type; return ctts[i].type;
} }
} }
return NULL; return NULL;

Просмотреть файл

@ -2021,7 +2021,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
else else
#endif #endif
if(conn->bits.conn_to_host) if(conn->bits.conn_to_host)
hostname = conn->conn_to_host.name; hostname = conn->conn_to_host.name;
else else
hostname = conn->host.name; hostname = conn->host.name;

Просмотреть файл

@ -295,7 +295,7 @@ static CURLcode oldap_parse_login_options(struct connectdata *conn)
const char *value; const char *value;
while(*ptr && *ptr != '=') while(*ptr && *ptr != '=')
ptr++; ptr++;
value = ptr + 1; value = ptr + 1;

Просмотреть файл

@ -1376,7 +1376,7 @@ static CURLcode pop3_parse_url_options(struct connectdata *conn)
const char *value; const char *value;
while(*ptr && *ptr != '=') while(*ptr && *ptr != '=')
ptr++; ptr++;
value = ptr + 1; value = ptr + 1;

Просмотреть файл

@ -542,7 +542,7 @@ static ssize_t cf_msh3_recv(struct Curl_cfilter *cf, struct Curl_easy *data,
if(nread < 0) if(nread < 0)
goto out; goto out;
if(stream->closed) if(stream->closed)
drain_stream(cf, data); drain_stream(cf, data);
} }
else if(stream->closed) { else if(stream->closed) {
nread = recv_closed_stream(cf, data, err); nread = recv_closed_stream(cf, data, err);

Просмотреть файл

@ -1710,7 +1710,7 @@ static CURLcode qng_verify_peer(struct Curl_cfilter *cf,
Curl_conn_get_host(data, cf->sockindex, &hostname, &disp_hostname, &port); Curl_conn_get_host(data, cf->sockindex, &hostname, &disp_hostname, &port);
snihost = Curl_ssl_snihost(data, hostname, NULL); snihost = Curl_ssl_snihost(data, hostname, NULL);
if(!snihost) if(!snihost)
return CURLE_PEER_FAILED_VERIFICATION; return CURLE_PEER_FAILED_VERIFICATION;
cf->conn->bits.multiplex = TRUE; /* at least potentially multiplexed */ cf->conn->bits.multiplex = TRUE; /* at least potentially multiplexed */
cf->conn->httpversion = 30; cf->conn->httpversion = 30;

Просмотреть файл

@ -1548,7 +1548,7 @@ static CURLcode sectransp_set_selected_ciphers(struct Curl_easy *data,
/* Skip separators */ /* Skip separators */
while(is_separator(*cipher_start)) while(is_separator(*cipher_start))
cipher_start++; cipher_start++;
if(*cipher_start == '\0') { if(*cipher_start == '\0') {
break; break;
} }

Просмотреть файл

@ -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' # 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)$/)) { if(($l =~ /(^.*(char|int|long|void|CURL|CURLM|CURLMsg|[cC]url_[A-Za-z_]+|struct [a-zA-Z_]+) *(\*+)) (\w+)/) && ($4 !~ /^(const|volatile)$/)) {
checkwarn("ASTERISKSPACE", checkwarn("ASTERISKSPACE",

Просмотреть файл

@ -884,7 +884,7 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */
ParameterError pe = GetSizeParameter(global, nextarg, "rate", &value); ParameterError pe = GetSizeParameter(global, nextarg, "rate", &value);
if(pe != PARAM_OK) if(pe != PARAM_OK)
return pe; return pe;
config->recvpersecond = value; config->recvpersecond = value;
config->sendpersecond = value; config->sendpersecond = value;
} }
@ -1060,7 +1060,7 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */
GetSizeParameter(global, nextarg, "max-filesize", &value); GetSizeParameter(global, nextarg, "max-filesize", &value);
if(pe != PARAM_OK) if(pe != PARAM_OK)
return pe; return pe;
config->max_filesize = value; config->max_filesize = value;
} }
break; break;

Просмотреть файл

@ -1878,7 +1878,7 @@ static CURLcode single_transfer(struct GlobalConfig *global,
if(config->dns_ipv4_addr) if(config->dns_ipv4_addr)
my_setopt_str(curl, CURLOPT_DNS_LOCAL_IP4, config->dns_ipv4_addr); my_setopt_str(curl, CURLOPT_DNS_LOCAL_IP4, config->dns_ipv4_addr);
if(config->dns_ipv6_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: */ /* new in libcurl 7.6.2: */
my_setopt_slist(curl, CURLOPT_TELNETOPTIONS, config->telnet_options); my_setopt_slist(curl, CURLOPT_TELNETOPTIONS, config->telnet_options);

Просмотреть файл

@ -44,12 +44,12 @@ static int loadfile(const char *filename, void **filedata, size_t *filesize)
else else
datasize = (size_t)cert_tell; datasize = (size_t)cert_tell;
if(continue_reading) if(continue_reading)
continue_reading = fseek(fInCert, 0, SEEK_SET) == 0; continue_reading = fseek(fInCert, 0, SEEK_SET) == 0;
if(continue_reading) if(continue_reading)
data = malloc(datasize + 1); data = malloc(datasize + 1);
if((!data) || if((!data) ||
((int)fread(data, datasize, 1, fInCert) != 1)) ((int)fread(data, datasize, 1, fInCert) != 1))
continue_reading = FALSE; continue_reading = FALSE;
fclose(fInCert); fclose(fInCert);
if(!continue_reading) { if(!continue_reading) {
free(data); free(data);

Просмотреть файл

@ -1095,7 +1095,7 @@ int main(int argc, char *argv[])
#ifdef USE_UNIX_SOCKETS #ifdef USE_UNIX_SOCKETS
if(socket_domain == AF_UNIX) if(socket_domain == AF_UNIX)
logmsg("Listening on unix socket %s", unix_socket); logmsg("Listening on unix socket %s", unix_socket);
else else
#endif #endif
logmsg("Listening on port %hu", port); logmsg("Listening on port %hu", port);