From cbf2f0747b32cf6d29b7eb5e6115cf83cc598e0b Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 11 Apr 2026 00:15:37 +0200 Subject: [PATCH] checksrc: update, fix new issues found Closes #1850 --- ci/checksrc-all.pl | 2 ++ ci/checksrc.pl | 29 +++++++++++++++++++++-------- example/ssh2.c | 8 ++++---- src/mbedtls.c | 2 +- src/misc.c | 4 ++-- tests/test_agent_forward_ok.c | 4 ++-- tests/test_ssh2.c | 10 +++++----- 7 files changed, 37 insertions(+), 22 deletions(-) diff --git a/ci/checksrc-all.pl b/ci/checksrc-all.pl index 4d73bbba..3d53c5f6 100755 --- a/ci/checksrc-all.pl +++ b/ci/checksrc-all.pl @@ -16,11 +16,13 @@ my @options = ( "-aaccept", "-aatoi", "-acalloc", + "-aclose", "-aCreateFileA", "-afclose", "-afopen", "-afprintf", "-afree", + "-afstat", "-amalloc", "-aprintf", "-arealloc", diff --git a/ci/checksrc.pl b/ci/checksrc.pl index cd5817a3..04b4793b 100755 --- a/ci/checksrc.pl +++ b/ci/checksrc.pl @@ -49,6 +49,8 @@ my @ignore_line; my %banfunc = ( "_access" => 1, + "_fstati64" => 1, + "_lseeki64" => 1, "_mbscat" => 1, "_mbsncat" => 1, "_open" => 1, @@ -70,6 +72,7 @@ my %banfunc = ( "atoi" => 1, "atol" => 1, "calloc" => 1, + "close" => 1, "CreateFile" => 1, "CreateFileA" => 1, "CreateFileW" => 1, @@ -80,9 +83,11 @@ my %banfunc = ( "free" => 1, "freeaddrinfo" => 1, "freopen" => 1, + "fstat" => 1, "getaddrinfo" => 1, "gets" => 1, "gmtime" => 1, + "llseek" => 1, "LoadLibrary" => 1, "LoadLibraryA" => 1, "LoadLibraryEx" => 1, @@ -90,6 +95,7 @@ my %banfunc = ( "LoadLibraryExW" => 1, "LoadLibraryW" => 1, "localtime" => 1, + "lseek" => 1, "malloc" => 1, "mbstowcs" => 1, "MoveFileEx" => 1, @@ -149,11 +155,12 @@ my %warnings = ( 'BRACEPOS' => 'wrong position for an open brace', 'BRACEWHILE' => 'A single space between open brace and while', 'COMMANOSPACE' => 'comma without following space', - "CLOSEBRACE" => 'close brace indent level vs line above is off', + 'CLOSEBRACE' => 'close brace indent level vs line above is off', 'COMMENTNOSPACEEND' => 'no space before */', 'COMMENTNOSPACESTART' => 'no space following /*', 'COPYRIGHT' => 'file missing a copyright statement', 'CPPCOMMENTS' => '// comment detected', + 'CPPSPACE' => 'space before preprocessor hash', 'DOBRACE' => 'A single space between do and open brace', 'EMPTYLINEBRACE' => 'Empty line before the open brace', 'EQUALSNOSPACE' => 'equals sign without following space', @@ -266,7 +273,7 @@ sub readlocalfile { sub checkwarn { my ($name, $num, $col, $file, $line, $msg, $error) = @_; - my $w=$error?"error":"warning"; + my $w=$error ? "error" : "warning"; my $nowarn=0; #if(!$warnings{$name}) { @@ -405,7 +412,7 @@ readskiplist(); readlocalfile($file); do { - if("$wlist" !~ / $file /) { + if($wlist !~ / $file /) { my $fullname = $file; $fullname = "$dir/$file" if($fullname !~ '^\.?\.?/'); scanfile($fullname); @@ -674,6 +681,11 @@ sub scanfile { $includes{$path} = $l; } + # detect leading space before the hash + if($l =~ /^([ \t]+)\#/) { + checkwarn("CPPSPACE", + $line, 0, $file, $l, "space before preprocessor hash"); + } # detect and strip preprocessor directives if($l =~ /^[ \t]*\#/) { # preprocessor line @@ -966,9 +978,11 @@ sub scanfile { my $bad = $2; my $prefix = $1; my $suff = $3; - checkwarn("BANNEDFUNC", - $line, length($prefix), $file, $ol, - "use of $bad is banned"); + if($prefix !~ /(->|\.)$/) { + checkwarn("BANNEDFUNC", + $line, length($prefix), $file, $ol, + "use of $bad is banned"); + } my $search = quotemeta($prefix . $bad . $suff); my $replace = $prefix . 'x' x (length($bad) + 1); $l =~ s/$search/$replace/; @@ -1175,7 +1189,7 @@ sub scanfile { # which are tracked in the Git repo and edited in the workdir, or # committed locally on the branch without being in upstream master. # - # The simple and naive test is to simply check for the current year, + # The simple and naive test is to check for the current year, # but updating the year even without an edit is against project policy # (and it would fail every file on January 1st). # @@ -1216,7 +1230,6 @@ sub scanfile { checksrc_endoffile($file); close($R); - } if($errors || $warnings || $verbose) { diff --git a/example/ssh2.c b/example/ssh2.c index d1bf3037..f05ade89 100644 --- a/example/ssh2.c +++ b/example/ssh2.c @@ -271,11 +271,11 @@ int main(int argc, char *argv[]) * See /etc/termcap for more options. This is useful when opening * an interactive shell. */ - #if 0 +#if 0 if(libssh2_channel_request_pty(channel, "vanilla")) { fprintf(stderr, "Failed requesting pty\n"); } - #endif +#endif if(argc > 5) { if(libssh2_channel_exec(channel, argv[5])) { @@ -285,12 +285,12 @@ int main(int argc, char *argv[]) /* Instead of just running a single command with libssh2_channel_exec, * a shell can be opened on the channel instead, for interactive use. * You usually want a pty allocated first in that case (see above). */ - #if 0 +#if 0 if(libssh2_channel_shell(channel)) { fprintf(stderr, "Unable to request shell on allocated pty\n"); goto shutdown; } - #endif +#endif /* At this point the shell can be interacted with using * libssh2_channel_read() diff --git a/src/mbedtls.c b/src/mbedtls.c index 576216e0..16881aa4 100644 --- a/src/mbedtls.c +++ b/src/mbedtls.c @@ -44,7 +44,7 @@ #include #if MBEDTLS_VERSION_NUMBER < 0x03010000 - #error "mbedTLS 3.1.0 or upper required" +#error "mbedTLS 3.1.0 or upper required" #endif /*******************************************************************/ diff --git a/src/misc.c b/src/misc.c index d42e1ede..cb2c1d8f 100644 --- a/src/misc.c +++ b/src/misc.c @@ -770,8 +770,8 @@ int _libssh2_gettimeofday(struct timeval *tp, void *tzp) (void)tzp; if(tp) { #ifdef _WIN32 - /* Offset between 1601-01-01 and 1970-01-01 in 100 nanosec units */ - #define _WIN32_FT_OFFSET (116444736000000000) +/* Offset between 1601-01-01 and 1970-01-01 in 100 nanosec units */ +#define _WIN32_FT_OFFSET (116444736000000000) union { libssh2_uint64_t ns100; /* time since 1 Jan 1601 in 100ns units */ diff --git a/tests/test_agent_forward_ok.c b/tests/test_agent_forward_ok.c index cc282c18..0f16e8a3 100644 --- a/tests/test_agent_forward_ok.c +++ b/tests/test_agent_forward_ok.c @@ -39,12 +39,12 @@ int test(LIBSSH2_SESSION *session) } channel = libssh2_channel_open_session(session); - #if 0 +#if 0 if(!channel) { printf("Error opening channel\n"); return 1; } - #endif +#endif rc = libssh2_channel_request_auth_agent(channel); if(rc) { diff --git a/tests/test_ssh2.c b/tests/test_ssh2.c index ca282de5..a143ceb2 100644 --- a/tests/test_ssh2.c +++ b/tests/test_ssh2.c @@ -66,11 +66,11 @@ int main(int argc, char *argv[]) (void)argc; (void)argv; - #ifdef _WIN32 - #define LIBSSH2_FALLBACK_USER_ENV "USERNAME" - #else - #define LIBSSH2_FALLBACK_USER_ENV "LOGNAME" - #endif +#ifdef _WIN32 +#define LIBSSH2_FALLBACK_USER_ENV "USERNAME" +#else +#define LIBSSH2_FALLBACK_USER_ENV "LOGNAME" +#endif if(getenv("USER")) username = getenv("USER");