]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
checksrc: fix SPACEBEFOREPAREN for conditions starting with "*"
authorDaniel Stenberg <daniel@haxx.se>
Thu, 27 Apr 2023 14:29:45 +0000 (16:29 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 27 Apr 2023 15:24:47 +0000 (17:24 +0200)
The open paren check wants to warn for spaces before open parenthesis
for if/while/for but also for any function call. In order to avoid
catching function pointer declarations, the logic allows a space if the
first character after the open parenthesis is an asterisk.

I also spotted what we did not include "switch" in the check but we should.

This check is a little lame, but we reduce this problem by not allowing
that space for if/while/for/switch.

Reported-by: Emanuele Torre
Closes #11044

14 files changed:
lib/cf-h1-proxy.c
lib/cfilters.c
lib/connect.c
lib/ftp.c
lib/hsts.c
lib/http_aws_sigv4.c
lib/mprintf.c
lib/urlapi.c
lib/vtls/bearssl.c
lib/vtls/sectransp.c
scripts/checksrc.pl
src/tool_paramhlp.c
src/tool_urlglob.c
src/tool_writeout_json.c

index 700c199b1add45a251f1dc4e0d96e33c138aa872..b42c4e60558d697a077388ddfa4bbd8172be425e 100644 (file)
@@ -1096,7 +1096,7 @@ static CURLcode cf_h1_proxy_connect(struct Curl_cfilter *cf,
 
 out:
   *done = (result == CURLE_OK) && tunnel_is_established(cf->ctx);
-  if (*done) {
+  if(*done) {
     cf->connected = TRUE;
     tunnel_free(cf, data);
   }
index a839f7910b0cee49c3a17072b637a377d00f6f09..067de23ccacb46b8b42dbbbf3b46a1bd28eb9f9a 100644 (file)
@@ -293,8 +293,8 @@ bool Curl_conn_cf_discard_sub(struct Curl_cfilter *cf,
 
   /* remove from sub-chain and destroy */
   DEBUGASSERT(cf);
-  while (*pprev) {
-    if (*pprev == cf) {
+  while(*pprev) {
+    if(*pprev == cf) {
       *pprev = discard->next;
       discard->next = NULL;
       found = TRUE;
index 87f5b2ed1f14580f5f9eb1c60fc7450247dd733c..78446bdd5d024f7d2b2aa350a54fa069cdcb59ec 100644 (file)
@@ -548,7 +548,7 @@ static CURLcode baller_connect(struct Curl_cfilter *cf,
     baller->result = Curl_conn_cf_connect(baller->cf, data, 0, connected);
 
     if(!baller->result) {
-      if (*connected) {
+      if(*connected) {
         baller->connected = TRUE;
         baller->is_done = TRUE;
       }
index 4ff68cc454cbcc2f3039905a0ec087e22554b87c..c868c2b6e4e6e3f54fc0e97cd4aef8ac1a1e4860 100644 (file)
--- a/lib/ftp.c
+++ b/lib/ftp.c
@@ -4180,7 +4180,7 @@ CURLcode ftp_parse_url_path(struct Curl_easy *data)
       size_t dirAlloc = 0;
       const char *str = rawPath;
       for(; *str != 0; ++str)
-        if (*str == '/')
+        if(*str == '/')
           ++dirAlloc;
 
       if(dirAlloc) {
index 64cbae10c9872df0cb4032a06f1de39fd338941c..661bf4d75c474275744c171d3cec8d101c83f076 100644 (file)
@@ -204,7 +204,7 @@ CURLcode Curl_hsts_parse(struct hsts *h, const char *hostname,
       p++;
     if(*p == ';')
       p++;
-  } while (*p);
+  } while(*p);
 
   if(!gotma)
     /* max-age is mandatory */
index 7d50cfff8fd4ec26064c56f74af11da5d079f57b..806016253fff1bd61f6066d0208ca94813d7e7ee 100644 (file)
@@ -192,7 +192,7 @@ static CURLcode make_headers(struct Curl_easy *data,
   }
 
 
-  if (*content_sha256_header) {
+  if(*content_sha256_header) {
     tmp_head = curl_slist_append(head, content_sha256_header);
     if(!tmp_head)
       goto fail;
index 5de935b1fe95ff1c4bd8257e3cbc3393406c1c5f..8e830438d47e49a65904ea8f80f3383d9d2c0a6d 100644 (file)
@@ -400,7 +400,7 @@ static int dprintf_Pass1(const char *format, struct va_stack *vto,
         /* out of allowed range */
         return 1;
 
-      switch (*fmt) {
+      switch(*fmt) {
       case 'S':
         flags |= FLAGS_ALT;
         /* FALLTHROUGH */
index 192fb165bceab8250f440ac52ee7a4c0b85e8bc7..8b95107d23f30958b4de3a5e302c9044fdab9674 100644 (file)
@@ -678,7 +678,7 @@ static int ipv4_normalize(struct dynbuf *host)
     parts[n] = l;
     c = endp;
 
-    switch (*c) {
+    switch(*c) {
     case '.' :
       if(n == 3)
         return HOST_BAD;
index a3a557c480220dcf4db412057326ee2614b68aa3..2b666ca6fea4b813875cb7323532f83bc34789e1 100644 (file)
@@ -897,7 +897,7 @@ static ssize_t bearssl_send(struct Curl_cfilter *cf, struct Curl_easy *data,
 
   for(;;) {
     *err = bearssl_run_until(cf, data, BR_SSL_SENDAPP);
-    if (*err != CURLE_OK)
+    if(*err)
       return -1;
     app = br_ssl_engine_sendapp_buf(&backend->ctx.eng, &applen);
     if(!app) {
index d59f2a8c02d5531a1b2ad6cb8bcef2b0ea19d5bb..618c0c5865a57b483095f75fcf59d898f6ab12e3 100644 (file)
@@ -1554,7 +1554,7 @@ static CURLcode sectransp_set_selected_ciphers(struct Curl_easy *data,
     }
     /* Find last position of a cipher in the ciphers string */
     cipher_end = cipher_start;
-    while (*cipher_end != '\0' && !is_separator(*cipher_end)) {
+    while(*cipher_end != '\0' && !is_separator(*cipher_end)) {
       ++cipher_end;
     }
 
index 2aab0ad8fb43493b3e847a2761104b81a3fdffe7..974184bbd27ce0b5a07043e42f2eef9507a30ec8 100755 (executable)
@@ -517,7 +517,8 @@ sub scanfile {
 
         my $nostr = nostrings($l);
         # check spaces after for/if/while/function call
-        if($nostr =~ /^(.*)(for|if|while| ([a-zA-Z0-9_]+)) \((.)/) {
+        if($nostr =~ /^(.*)(for|if|while|switch| ([a-zA-Z0-9_]+)) \((.)/) {
+            my ($leading, $word, $extra, $first)=($1,$2,$3,$4);
             if($1 =~ / *\#/) {
                 # this is a #if, treat it differently
             }
@@ -527,15 +528,16 @@ sub scanfile {
             elsif(defined $3 && $3 eq "case") {
                 # case must have a space
             }
-            elsif($4 eq "*") {
-                # (* beginning makes the space OK!
+            elsif(($first eq "*") && ($word !~ /(for|if|while|switch)/)) {
+                # A "(*" beginning makes the space OK because it wants to
+                # allow funcion pointer declared
             }
             elsif($1 =~ / *typedef/) {
                 # typedefs can use space-paren
             }
             else {
-                checkwarn("SPACEBEFOREPAREN", $line, length($1)+length($2), $file, $l,
-                          "$2 with space");
+                checkwarn("SPACEBEFOREPAREN", $line, length($leading)+length($word), $file, $l,
+                          "$word with space");
             }
         }
         # check for '== NULL' in if/while conditions but not if the thing on
index 52f9fdefb114da1acaf1b3517b5d09e03b4da21b..bfcb6fcb4d7684210dc4bbff5eca37d21762060f 100644 (file)
@@ -369,7 +369,7 @@ ParameterError proto2num(struct OperationConfig *config,
 
     /* Process token modifiers */
     while(!ISALNUM(*token)) { /* may be NULL if token is all modifiers */
-      switch (*token++) {
+      switch(*token++) {
       case '=':
         action = set;
         break;
index 44dd9a748c49bf2b007e4828004253241623bf09..fe1ce64c6565ca0a154e9e00cc6b30dbbc1c74d1 100644 (file)
@@ -100,7 +100,7 @@ static CURLcode glob_set(struct URLGlob *glob, char **patternp,
   pat->globindex = globindex;
 
   while(!done) {
-    switch (*pattern) {
+    switch(*pattern) {
     case '\0':                  /* URL ended while set was still open */
       return GLOBERROR("unmatched brace", opos, CURLE_URL_MALFORMAT);
 
@@ -411,7 +411,7 @@ static CURLcode glob_parse(struct URLGlob *glob, char *pattern,
       res = glob_fixed(glob, glob->glob_buffer, sublen);
     }
     else {
-      switch (*pattern) {
+      switch(*pattern) {
       case '\0': /* done  */
         break;
 
index 6f21f2b2de546c113ab2631fbeabd1fd9c5f017d..ec9c640b5ed73d39acf796149bf4c14ddb1dc438 100644 (file)
@@ -61,7 +61,7 @@ void jsonWriteString(FILE *stream, const char *in, bool lowercase)
       fputs("\\t", stream);
       break;
     default:
-      if (*i < 32) {
+      if(*i < 32) {
         fprintf(stream, "u%04x", *i);
       }
       else {