]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
checksrc: warn for leading spaces before the preprocessor hash
authorDaniel Stenberg <daniel@haxx.se>
Tue, 13 Jan 2026 08:23:21 +0000 (09:23 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 13 Jan 2026 08:52:26 +0000 (09:52 +0100)
Fix the 40+ fallouts

Closes #20282

lib/curl_ntlm_core.c
lib/file.c
lib/http_negotiate.c
lib/md4.c
lib/md5.c
lib/sha256.c
lib/vquic/curl_ngtcp2.c
lib/vssh/libssh.c
scripts/checksrc.pl
tests/data/test1185

index 2f4f7c3abdb9cbaaecd2a4dcfc2811b6c92c7cab..62599174a3c1fb48811a3cd13b5f2f79719eed3f 100644 (file)
 #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
index 9ba536bf2ea706e96ee9dc8bc60868e3064e47ad..ef4fc8042f8128f29517c0a29442f3ef6dc8bec3 100644 (file)
@@ -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 */
index be1063d92d29fbe4cac04237f1b83a7b85228c52..a6e5c19ec44aeb7dd3378f8a70edbae8f5b7811f 100644 (file)
@@ -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) {
index e7ecf58ec8a9909e6d491bc3a0fa323db0f8f1e6..33531fe9cac5e5f9df3658cbba04501439ecb5fd 100644 (file)
--- a/lib/md4.c
+++ b/lib/md4.c
 #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)
index 3e068cc59fe0e84a2aef4e8bbcef132f1d5d8d37..c0a8acc709f85de58030d8318706a70b4d1d0c91 100644 (file)
--- a/lib/md5.c
+++ b/lib/md5.c
 #include "curl_hmac.h"
 
 #ifdef USE_OPENSSL
-  #include <openssl/opensslconf.h>
-  #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_DEPRECATED_3_0)
-    #define USE_OPENSSL_MD5
-  #endif
+#include <openssl/opensslconf.h>
+#if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_DEPRECATED_3_0)
+#define USE_OPENSSL_MD5
+#endif
 #endif
 
 #ifdef USE_WOLFSSL
-  #include <wolfssl/options.h>
-  #ifndef NO_MD5
-    #define USE_WOLFSSL_MD5
-  #endif
+#include <wolfssl/options.h>
+#ifndef NO_MD5
+#define USE_WOLFSSL_MD5
+#endif
 #endif
 
 #ifdef USE_MBEDTLS
-  #include <mbedtls/version.h>
-  #if MBEDTLS_VERSION_NUMBER < 0x03020000
-    #error "mbedTLS 3.2.0 or later required"
-  #endif
-  #include <psa/crypto_config.h>
-  #if defined(PSA_WANT_ALG_MD5) && PSA_WANT_ALG_MD5  /* mbedTLS 4+ */
-    #define USE_MBEDTLS_MD5
-  #endif
+#include <mbedtls/version.h>
+#if MBEDTLS_VERSION_NUMBER < 0x03020000
+#error "mbedTLS 3.2.0 or later required"
+#endif
+#include <psa/crypto_config.h>
+#if defined(PSA_WANT_ALG_MD5) && PSA_WANT_ALG_MD5  /* mbedTLS 4+ */
+#define USE_MBEDTLS_MD5
+#endif
 #endif
 
 #ifdef USE_GNUTLS
index dbce88f46fefe6098f8f73068b86f627789840a7..9f31202ccaeabc8025bccfcffeba20c64c85b344 100644 (file)
 #include "curl_sha256.h"
 
 #ifdef USE_MBEDTLS
-  #include <mbedtls/version.h>
-  #if MBEDTLS_VERSION_NUMBER < 0x03020000
-    #error "mbedTLS 3.2.0 or later required"
-  #endif
-  #include <psa/crypto_config.h>
-  #if defined(PSA_WANT_ALG_SHA_256) && PSA_WANT_ALG_SHA_256  /* mbedTLS 4+ */
-    #define USE_MBEDTLS_SHA256
-  #endif
+#include <mbedtls/version.h>
+#if MBEDTLS_VERSION_NUMBER < 0x03020000
+#error "mbedTLS 3.2.0 or later required"
+#endif
+#include <psa/crypto_config.h>
+#if defined(PSA_WANT_ALG_SHA_256) && PSA_WANT_ALG_SHA_256  /* mbedTLS 4+ */
+#define USE_MBEDTLS_SHA256
+#endif
 #endif
 
 #ifdef USE_OPENSSL
index 071f38a70d2062228de6582e9180f24237af598b..5c615616c29717b81a4fe54c1a56860e4f95526f 100644 (file)
@@ -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);
index aa029d3b7aa53a3dafa1d47123997cddab892737..7a4060b07a6064dc5251e7b80bec75c5fe3d214a 100644 (file)
@@ -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"
index fc9fbd920904b887bb0039020e4c20cfeafe3722..21d4782c7def68dcf6a31bf2693dd89a10c6753e 100755 (executable)
@@ -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
index 7af7b79a2f69cbbd310803ccc2778cb10abb9500..3f7cd9fb70c21fbb5f59af0559b573cebac16eb8 100644 (file)
@@ -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
 </stdout>
 <errorcode>
 5