From: Daniel Stenberg Date: Tue, 13 Jan 2026 08:23:21 +0000 (+0100) Subject: checksrc: warn for leading spaces before the preprocessor hash X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f057ed05beb2f03eb77dab446d8ff9c3f62cac42;p=thirdparty%2Fcurl.git checksrc: warn for leading spaces before the preprocessor hash Fix the 40+ fallouts Closes #20282 --- diff --git a/lib/curl_ntlm_core.c b/lib/curl_ntlm_core.c index 2f4f7c3abd..62599174a3 100644 --- a/lib/curl_ntlm_core.c +++ b/lib/curl_ntlm_core.c @@ -57,11 +57,11 @@ #endif #if defined(USE_OPENSSL) && defined(HAVE_DES_ECB_ENCRYPT) - #define USE_OPENSSL_DES +# define USE_OPENSSL_DES #elif defined(USE_WOLFSSL) && defined(HAVE_WOLFSSL_DES_ECB_ENCRYPT) - #define USE_OPENSSL_DES +# define USE_OPENSSL_DES #elif defined(USE_MBEDTLS) && defined(HAVE_MBEDTLS_DES_CRYPT_ECB) - #define USE_MBEDTLS_DES +# define USE_MBEDTLS_DES #endif #ifdef USE_OPENSSL_DES diff --git a/lib/file.c b/lib/file.c index 9ba536bf2e..ef4fc8042f 100644 --- a/lib/file.c +++ b/lib/file.c @@ -204,7 +204,7 @@ static CURLcode file_connect(struct Curl_easy *data, bool *done) return CURLE_URL_MALFORMAT; } - #ifdef AMIGA_FILESYSTEM +#ifdef AMIGA_FILESYSTEM /* * A leading slash in an AmigaDOS path denotes the parent * directory, and hence we block this as it is relative. @@ -227,10 +227,10 @@ static CURLcode file_connect(struct Curl_easy *data, bool *done) fd = curlx_open(real_path, O_RDONLY); } } - #else +#else fd = curlx_open(real_path, O_RDONLY); file->path = real_path; - #endif +#endif #endif curlx_free(file->freepath); file->freepath = real_path; /* free this when done */ diff --git a/lib/http_negotiate.c b/lib/http_negotiate.c index be1063d92d..a6e5c19ec4 100644 --- a/lib/http_negotiate.c +++ b/lib/http_negotiate.c @@ -233,19 +233,19 @@ CURLcode Curl_output_negotiate(struct Curl_easy *data, } *state = GSS_AUTHSENT; - #ifdef HAVE_GSSAPI +#ifdef HAVE_GSSAPI if(neg_ctx->status == GSS_S_COMPLETE || neg_ctx->status == GSS_S_CONTINUE_NEEDED) { *state = GSS_AUTHDONE; } - #else - #ifdef USE_WINDOWS_SSPI +#else +#ifdef USE_WINDOWS_SSPI if(neg_ctx->status == SEC_E_OK || neg_ctx->status == SEC_I_CONTINUE_NEEDED) { *state = GSS_AUTHDONE; } - #endif - #endif +#endif +#endif } if(*state == GSS_AUTHDONE || *state == GSS_AUTHSUCC) { diff --git a/lib/md4.c b/lib/md4.c index e7ecf58ec8..33531fe9ca 100644 --- a/lib/md4.c +++ b/lib/md4.c @@ -70,10 +70,10 @@ #if defined(USE_WOLFSSL) && !defined(WOLFSSL_NO_MD4) #ifdef OPENSSL_COEXIST - #define MD4_CTX WOLFSSL_MD4_CTX - #define MD4_Init wolfSSL_MD4_Init - #define MD4_Update wolfSSL_MD4_Update - #define MD4_Final wolfSSL_MD4_Final +# define MD4_CTX WOLFSSL_MD4_CTX +# define MD4_Init wolfSSL_MD4_Init +# define MD4_Update wolfSSL_MD4_Update +# define MD4_Final wolfSSL_MD4_Final #endif #elif defined(USE_OPENSSL) && !defined(OPENSSL_NO_MD4) diff --git a/lib/md5.c b/lib/md5.c index 3e068cc59f..c0a8acc709 100644 --- a/lib/md5.c +++ b/lib/md5.c @@ -30,28 +30,28 @@ #include "curl_hmac.h" #ifdef USE_OPENSSL - #include - #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_DEPRECATED_3_0) - #define USE_OPENSSL_MD5 - #endif +#include +#if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_DEPRECATED_3_0) +#define USE_OPENSSL_MD5 +#endif #endif #ifdef USE_WOLFSSL - #include - #ifndef NO_MD5 - #define USE_WOLFSSL_MD5 - #endif +#include +#ifndef NO_MD5 +#define USE_WOLFSSL_MD5 +#endif #endif #ifdef USE_MBEDTLS - #include - #if MBEDTLS_VERSION_NUMBER < 0x03020000 - #error "mbedTLS 3.2.0 or later required" - #endif - #include - #if defined(PSA_WANT_ALG_MD5) && PSA_WANT_ALG_MD5 /* mbedTLS 4+ */ - #define USE_MBEDTLS_MD5 - #endif +#include +#if MBEDTLS_VERSION_NUMBER < 0x03020000 +#error "mbedTLS 3.2.0 or later required" +#endif +#include +#if defined(PSA_WANT_ALG_MD5) && PSA_WANT_ALG_MD5 /* mbedTLS 4+ */ +#define USE_MBEDTLS_MD5 +#endif #endif #ifdef USE_GNUTLS diff --git a/lib/sha256.c b/lib/sha256.c index dbce88f46f..9f31202cca 100644 --- a/lib/sha256.c +++ b/lib/sha256.c @@ -30,14 +30,14 @@ #include "curl_sha256.h" #ifdef USE_MBEDTLS - #include - #if MBEDTLS_VERSION_NUMBER < 0x03020000 - #error "mbedTLS 3.2.0 or later required" - #endif - #include - #if defined(PSA_WANT_ALG_SHA_256) && PSA_WANT_ALG_SHA_256 /* mbedTLS 4+ */ - #define USE_MBEDTLS_SHA256 - #endif +#include +#if MBEDTLS_VERSION_NUMBER < 0x03020000 +#error "mbedTLS 3.2.0 or later required" +#endif +#include +#if defined(PSA_WANT_ALG_SHA_256) && PSA_WANT_ALG_SHA_256 /* mbedTLS 4+ */ +#define USE_MBEDTLS_SHA256 +#endif #endif #ifdef USE_OPENSSL diff --git a/lib/vquic/curl_ngtcp2.c b/lib/vquic/curl_ngtcp2.c index 071f38a70d..5c615616c2 100644 --- a/lib/vquic/curl_ngtcp2.c +++ b/lib/vquic/curl_ngtcp2.c @@ -2639,7 +2639,7 @@ static CURLcode cf_connect_start(struct Curl_cfilter *cf, #elif defined(USE_WOLFSSL) ngtcp2_conn_set_tls_native_handle(ctx->qconn, ctx->tls.wssl.ssl); #else - #error "ngtcp2 TLS backend not defined" +#error "ngtcp2 TLS backend not defined" #endif ngtcp2_ccerr_default(&ctx->last_error); diff --git a/lib/vssh/libssh.c b/lib/vssh/libssh.c index aa029d3b7a..7a4060b07a 100644 --- a/lib/vssh/libssh.c +++ b/lib/vssh/libssh.c @@ -751,11 +751,11 @@ static int myssh_in_SFTP_QUOTE_STATVFS(struct Curl_easy *data, return SSH_OK; } else if(statvfs) { - #ifdef _MSC_VER - #define CURL_LIBSSH_VFS_SIZE_MASK "I64u" - #else - #define CURL_LIBSSH_VFS_SIZE_MASK PRIu64 - #endif +#ifdef _MSC_VER +#define CURL_LIBSSH_VFS_SIZE_MASK "I64u" +#else +#define CURL_LIBSSH_VFS_SIZE_MASK PRIu64 +#endif CURLcode result = CURLE_OK; char *tmp = curl_maprintf("statvfs:\n" "f_bsize: %" CURL_LIBSSH_VFS_SIZE_MASK "\n" diff --git a/scripts/checksrc.pl b/scripts/checksrc.pl index fc9fbd9209..21d4782c7d 100755 --- a/scripts/checksrc.pl +++ b/scripts/checksrc.pl @@ -152,6 +152,7 @@ my %warnings = ( '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', @@ -672,6 +673,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 diff --git a/tests/data/test1185 b/tests/data/test1185 index 7af7b79a2f..3f7cd9fb70 100644 --- a/tests/data/test1185 +++ b/tests/data/test1185 @@ -218,6 +218,9 @@ void startfunc(int a, int b) { ./%LOGDIR/code1185.c:65:1: warning: use ifdef/ifndef for single macro checks (IFDEFSINGLE) #if ! defined(__macro_10) ^ +./%LOGDIR/code1185.c:65:1: warning: space before preprocessor hash (CPPSPACE) + #if ! defined(__macro_10) + ^ ./%LOGDIR/code1185.c:71:2: warning: // comment (CPPCOMMENTS) // CPP comment ? ^ @@ -227,7 +230,7 @@ void startfunc(int a, int b) { ./%LOGDIR/code1185.c:1:1: error: Missing closing comment (OPENCOMMENT) %SP ^ -checksrc: 0 errors and 44 warnings +checksrc: 0 errors and 45 warnings 5