clang-tidy: add to CI, add cmake support, fix fallouts

build:
- autotools: fix to build generated sources for the `tidy` target.
- autotools: allow passing custom clang-tidy options via
  `CURL_CLANG_TIDYFLAGS` env.
- cmake: add `CURL_CLANG_TIDY` option to configure for `clang-tidy`.
  Also add:
  - `CLANG_TIDY` variable to customize the `clang-tidy` tool.
  - `CURL_CLANG_TIDYFLAGS` to pass custom options to `clang-tidy`.
- apply `--enable-werror` and `-DCURL_WERROR=ON` to `clang-tidy`.

CI/GHA:
- add clang-tidy job for Linux, using autotools and clang-tidy v18.
  This one needs to disable `clang-analyzer-valist.Uninitialized`
  to avoid false positives:
  https://github.com/llvm/llvm-project/issues/40656
  Duration: 5.5 minutes
- add clang-tidy job for macOS, using cmake and clang-tidy v19.
  This one also covers tests and examples, and doesn't hit the false
  positives seen with llvm v18 and earlier.
  Duration: 4.5 minutes
- Linux/macOS: skip installing test dependencies when not building or
  running tests.

fix fallouts reported by `clang-tidy`:
- lib:
  - cf-h2-proxy: unused assignment in non-debug builds.
  - cf-socket: silence warning.
    FIXME: https://github.com/curl/curl/pull/15825#issuecomment-2561867769
  - ftp: NULL passed to `strncmp()`.
  - http2: NULL-ptr deref.
  - mprintf: silence warning.
- src/tool_writeout: NULL passed to `fputs()`.
- examples:
  - invalid file pointers.
  - missing `fclose()`.
- tests:
  - http/clients/hx-download: memory leaks on error.
  - http/clients/hx-download: memory leak on repeat `-r` option.
  - server: double `fclose()`.
    https://www.man7.org/linux/man-pages/man3/fclose.3.html
  - server: invalid file pointer/handle.
  - server/getpart: unused assignments.
  - server/mqttd: leak on failed `realloc()`.
  - server/tftpd: NULL passed to `strcmp()`.

Closes #15825
This commit is contained in:
Viktor Szakats 2024-12-24 02:43:02 +01:00
parent 421e592db2
commit fabfa8e402
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
27 changed files with 134 additions and 68 deletions

View file

@ -313,12 +313,14 @@ int main(int argc, char *argv[])
char *resolve = NULL;
size_t max_host_conns = 0;
int fresh_connect = 0;
int result = 0;
while((ch = getopt(argc, argv, "aefhm:n:xA:F:M:P:r:V:")) != -1) {
switch(ch) {
case 'h':
usage(NULL);
return 2;
result = 2;
goto cleanup;
case 'a':
abort_paused = 1;
break;
@ -350,6 +352,7 @@ int main(int argc, char *argv[])
pause_offset = (size_t)strtol(optarg, NULL, 10);
break;
case 'r':
free(resolve);
resolve = strdup(optarg);
break;
case 'V': {
@ -361,13 +364,15 @@ int main(int argc, char *argv[])
http_version = CURL_HTTP_VERSION_3ONLY;
else {
usage("invalid http version");
return 1;
result = 1;
goto cleanup;
}
break;
}
default:
usage("invalid option");
return 1;
usage("invalid option");
result = 1;
goto cleanup;
}
}
argc -= optind;
@ -378,7 +383,8 @@ int main(int argc, char *argv[])
if(argc != 1) {
usage("not enough arguments");
return 2;
result = 2;
goto cleanup;
}
url = argv[0];
@ -388,7 +394,8 @@ int main(int argc, char *argv[])
share = curl_share_init();
if(!share) {
fprintf(stderr, "error allocating share\n");
return 1;
result = 1;
goto cleanup;
}
curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE);
curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_DNS);
@ -400,7 +407,8 @@ int main(int argc, char *argv[])
transfers = calloc(transfer_count, sizeof(*transfers));
if(!transfers) {
fprintf(stderr, "error allocating transfer structs\n");
return 1;
result = 1;
goto cleanup;
}
multi_handle = curl_multi_init();
@ -425,7 +433,8 @@ int main(int argc, char *argv[])
setup(t->easy, url, t, http_version, host, share, use_earlydata,
fresh_connect)) {
fprintf(stderr, "[t-%d] FAILED setup\n", (int)i);
return 1;
result = 1;
goto cleanup;
}
curl_multi_add_handle(multi_handle, t->easy);
t->started = 1;
@ -468,7 +477,6 @@ int main(int argc, char *argv[])
}
}
/* nothing happening, maintenance */
if(abort_paused) {
/* abort paused transfers */
@ -505,7 +513,8 @@ int main(int argc, char *argv[])
setup(t->easy, url, t, http_version, host, share,
use_earlydata, fresh_connect)) {
fprintf(stderr, "[t-%d] FAILED setup\n", (int)i);
return 1;
result = 1;
goto cleanup;
}
curl_multi_add_handle(multi_handle, t->easy);
t->started = 1;
@ -539,9 +548,10 @@ int main(int argc, char *argv[])
curl_share_cleanup(share);
curl_slist_free_all(host);
cleanup:
free(resolve);
return 0;
return result;
#else
(void)argc;
(void)argv;