cmake: replace the way clang-tidy verifies tests, fix issues found

Replace existing `mk-unity.pl` `--embed` workaround with running
`clang-tidy` manually on individual test source instead. This aligns
with how clang-tidy works and removes `mk-unity.pl` from the solution.

Also:
- mqttd: fix potentially uninitialized buffer by zero filling it.
  ```
  tests/server/mqttd.c:484:41: error: The left operand of '<<' is a garbage value
    [clang-analyzer-core.UndefinedBinaryOperatorResult,-warnings-as-errors]
    484 |       payload_len = (size_t)(buffer[10] << 8) | buffer[11];
        |                                         ^
  [...]
  tests/server/mqttd.c:606:45: error: The left operand of '<<' is a garbage value
    [clang-analyzer-core.UndefinedBinaryOperatorResult,-warnings-as-errors]
    606 |       topiclen = (size_t)(buffer[1 + bytes] << 8) | buffer[2 + bytes];
        |                                             ^
  ```
- sockfilt: fix potential out-of-bound pointer:
  ```
  tests/server/sockfilt.c:1128:33: error: The 2nd argument to 'send' is a buffer
     with size 17010 but should be a buffer with size equal to or greater than
     the value of the 3rd argument (which is 18446744073709551615)
     [clang-analyzer-unix.StdCLibraryFunctions,-warnings-as-errors]
   1128 |         ssize_t bytes_written = swrite(sockfd, buffer, buffer_len);
        |                                 ^
  ```
- clang-tidy: suppress bogus `bzero()` warnings that happens
  inside the notorious `FD_ZERO()` macros, on macOS.

Ref: https://github.com/curl/curl/pull/17680#issuecomment-2991730158

Closes #17705
This commit is contained in:
Viktor Szakats 2025-06-22 03:17:33 +02:00
parent 9837dd429a
commit e088e10454
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
14 changed files with 111 additions and 50 deletions

View file

@ -31,16 +31,13 @@ use strict;
use warnings;
if(!@ARGV) {
die "Usage: $0 [--test <tests>] [--include <include-c-sources>] [--srcdir <srcdir>] [--embed]\n";
die "Usage: $0 [--test <tests>] [--include <include-c-sources>]\n";
}
my @src;
my %include;
my $in_include = 0;
my $srcdir = "";
my $in_srcdir = 0;
my $any_test = 0;
my $embed = 0;
foreach my $src (@ARGV) {
if($src eq "--test") {
$in_include = 0;
@ -48,16 +45,6 @@ foreach my $src (@ARGV) {
elsif($src eq "--include") {
$in_include = 1;
}
elsif($src eq "--embed") {
$embed = 1;
}
elsif($src eq "--srcdir") {
$in_srcdir = 1;
}
elsif($in_srcdir) {
$srcdir = $src;
$in_srcdir = 0;
}
elsif($in_include) {
$include{$src} = 1;
push @src, $src;
@ -78,18 +65,7 @@ my $tlist = "";
foreach my $src (@src) {
if($src =~ /([a-z0-9_]+)\.c$/) {
my $name = $1;
if($embed) {
my $fn = $src;
if($srcdir ne "" && -e "$srcdir/$fn") {
$fn = $srcdir . "/" . $fn;
}
print "/* Embedding: \"$src\" */\n";
my $content = do { local $/; open my $fh, '<', $fn or die $!; <$fh> };
print $content;
}
else {
print "#include \"$src\"\n";
}
print "#include \"$src\"\n";
if(not exists $include{$src}) { # register test entry function
$tlist .= " {\"$name\", test_$name},\n";
}