]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
checksrc: ensure using `ifdef`/`ifndef` when possible, fix fallouts
authorViktor Szakats <commit@vsz.me>
Sun, 21 Dec 2025 14:45:53 +0000 (15:45 +0100)
committerViktor Szakats <commit@vsz.me>
Sun, 21 Dec 2025 20:12:31 +0000 (21:12 +0100)
Follow-up to 89771d19d58d16cfe6e1d7fda7acd65a0a316eba #18018

Closes #20065

lib/amigaos.c
lib/setopt.c
lib/url.c
lib/vssh/libssh.c
lib/vssh/libssh2.c
lib/vtls/apple.c
scripts/checksrc.pl
src/tool_cb_soc.c
tests/data/test1185

index 4e5960b8f5e4c7e6919d0b4c99dc03a387ee2047..76d67b08fea4eda723ee027703a01f03f1dd2fd4 100644 (file)
@@ -30,7 +30,7 @@
 #include "amigaos.h"
 
 #ifdef HAVE_PROTO_BSDSOCKET_H
-#  if defined(__amigaos4__)
+#  ifdef __amigaos4__
 #    include <bsdsocket/socketbasetags.h>
 #  elif !defined(USE_AMISSL)
 #    include <amitcp/socketbasetags.h>
index 2bdb6a3473b411692ff8ee8d465e753e5d0b3e26..118c4d05554b01cbb72c70bd5032c9f2f16b5c49 100644 (file)
@@ -521,7 +521,7 @@ static CURLcode setopt_bool(struct Curl_easy *data, CURLoption option,
   case CURLOPT_HTTP09_ALLOWED:
     s->http09_allowed = enabled;
     break;
-#if !defined(CURL_DISABLE_COOKIES)
+#ifndef CURL_DISABLE_COOKIES
   case CURLOPT_COOKIESESSION:
     /*
      * Set this option to TRUE to start a new "cookie session". It will
index 7f439b5449fc4569be994bffa02766e974143281..5340f5a4c99dcbd37bbfbec6125c913bf81a109f 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
@@ -1527,7 +1527,7 @@ const struct Curl_handler *Curl_getn_scheme_handler(const char *scheme,
 #else
     NULL,
 #endif
-#if defined(USE_SSH)
+#ifdef USE_SSH
     &Curl_handler_scp,
 #else
     NULL,
index 327f3ee661628f0d8b76a03b43b58d0017d691ec..7d5905c83d759f22956a00c4f244b3c27be56c35 100644 (file)
@@ -204,7 +204,7 @@ static CURLcode sftp_error_to_CURLE(int err)
   return CURLE_SSH;
 }
 
-#if !defined(CURL_DISABLE_VERBOSE_STRINGS)
+#ifndef CURL_DISABLE_VERBOSE_STRINGS
 static const char *myssh_statename(sshstate state)
 {
   static const char * const names[] = {
@@ -287,7 +287,7 @@ static void myssh_set_state(struct Curl_easy *data,
                             struct ssh_conn *sshc,
                             sshstate nowstate)
 {
-#if !defined(CURL_DISABLE_VERBOSE_STRINGS)
+#ifndef CURL_DISABLE_VERBOSE_STRINGS
   if(sshc->state != nowstate) {
     CURL_TRC_SSH(data, "[%s] -> [%s]",
                  myssh_statename(sshc->state),
index 3f81dbd853b1a95ef6814b38b2e7ac3dbcb1b7d2..4d43ddd9f1287cef4350af9159e726ea9af55814 100644 (file)
@@ -274,7 +274,7 @@ static LIBSSH2_FREE_FUNC(my_libssh2_free)
     Curl_cfree(ptr);
 }
 
-#if !defined(CURL_DISABLE_VERBOSE_STRINGS)
+#ifndef CURL_DISABLE_VERBOSE_STRINGS
 static const char *myssh_statename(sshstate state)
 {
   static const char * const names[] = {
@@ -357,7 +357,7 @@ static void myssh_set_state(struct Curl_easy *data,
                             struct ssh_conn *sshc,
                             sshstate nowstate)
 {
-#if !defined(CURL_DISABLE_VERBOSE_STRINGS)
+#ifndef CURL_DISABLE_VERBOSE_STRINGS
   if(sshc->state != nowstate) {
     CURL_TRC_SSH(data, "[%s] -> [%s]",
                  myssh_statename(sshc->state),
index f076caf5ffa25c53fb1e4b0734b3fcf1bed66b61..0b81e95e86f772017eb750e5792a16ac1cb40273 100644 (file)
@@ -225,7 +225,7 @@ CURLcode Curl_vtls_apple_verify(struct Curl_cfilter *cf,
 #endif
 
 #ifdef SUPPORTS_SecTrustEvaluateWithError
-#if defined(HAVE_BUILTIN_AVAILABLE)
+#ifdef HAVE_BUILTIN_AVAILABLE
   if(__builtin_available(macOS 10.14, iOS 12, tvOS 12, watchOS 5, *)) {
 #else
   if(1) {
index 33cd4bb246ce6a09f12a5f6b3218d3bc1bfce091..8839f38bf610a024d87d96238340af5b106e643c 100755 (executable)
@@ -162,6 +162,7 @@ my %warnings = (
     'EXCLAMATIONSPACE'      => 'Whitespace after exclamation mark in expression',
     'FIXME'                 => 'FIXME or TODO comment',
     'FOPENMODE'             => 'fopen needs a macro for the mode string',
+    'IFDEFSINGLE',          => 'use ifdef/ifndef for single macro checks',
     'INCLUDEDUP',           => 'same file is included again',
     'INDENTATION'           => 'wrong start column for code',
     'LONGLINE'              => "Line longer than $max_column",
@@ -658,6 +659,11 @@ sub scanfile {
                       $line, length($1), $file, $l, "\/\/ comment");
         }
 
+        if($l =~ /^\s*#\s*if\s+!?\s*defined\([a-zA-Z0-9_]+\)$/) {
+            checkwarn("IFDEFSINGLE",
+                      $line, length($1), $file, $l, "use ifdef/ifndef for single macro checks");
+        }
+
         if($l =~ /^(\#\s*include\s+)([\">].*[>}"])/) {
             my ($pre, $path) = ($1, $2);
             if($includes{$path}) {
index d89870297cdbdc9ca8c5da2d20d778dbd18506aa..0df0a1e6fb2427940016e7262ae1efdf3fb067e6 100644 (file)
@@ -45,7 +45,7 @@ curl_socket_t tool_socket_open_mptcp_cb(void *clientp,
   (void)purpose;
 
   if(protocol == IPPROTO_TCP)
-#if defined(__linux__)
+#ifdef __linux__
 #  ifndef IPPROTO_MPTCP
 #  define IPPROTO_MPTCP 262
 #  endif
index 71654f7ba72ad08fb5e1fd2eea3599ae63a1ed79..7af7b79a2f69cbbd310803ccc2778cb10abb9500 100644 (file)
@@ -79,6 +79,13 @@ void startfunc(int a, int b) {
  if(sprintf(buffer, "%s", moo)) {}
  *buffer_len = (ssize_t)alsobad((char *)buffer, NULL, 16);
 
+# if defined(SINGLE_MACRO)
+ #if  ! defined(__macro_10)
+#elif !defined(TESTMACRO)
+#endif
+#endif
+#endif
+
  // CPP comment ?
 
  /* comment does not end
@@ -205,7 +212,13 @@ void startfunc(int a, int b) {
 ./%LOGDIR/code1185.c:62:25: warning: use of alsobad is banned (BANNEDFUNC)
   *buffer_len = (ssize_t)alsobad((char *)buffer, NULL, 16);
                          ^
-./%LOGDIR/code1185.c:64:2: warning: // comment (CPPCOMMENTS)
+./%LOGDIR/code1185.c:64:1: warning: use ifdef/ifndef for single macro checks (IFDEFSINGLE)
+ # if defined(SINGLE_MACRO)
+ ^
+./%LOGDIR/code1185.c:65:1: warning: use ifdef/ifndef for single macro checks (IFDEFSINGLE)
+  #if  ! defined(__macro_10)
+ ^
+./%LOGDIR/code1185.c:71:2: warning: // comment (CPPCOMMENTS)
   // CPP comment ?
   ^
 ./%LOGDIR/code1185.c:1:1: error: Missing copyright statement (COPYRIGHT)
@@ -214,7 +227,7 @@ void startfunc(int a, int b) {
 ./%LOGDIR/code1185.c:1:1: error: Missing closing comment (OPENCOMMENT)
 %SP
  ^
-checksrc: 0 errors and 42 warnings
+checksrc: 0 errors and 44 warnings
 </stdout>
 <errorcode>
 5