From: Frank Lichtenheld Date: Sat, 8 Aug 2026 13:31:58 +0000 (+0200) Subject: Hide various functions when unused X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;p=thirdparty%2Fopenvpn.git Hide various functions when unused Wrap them into the same ifdef as their only user(s). Identified by cppcheck. Change-Id: I81b7168b64c438f759eace1e8f2735891c797bb9 Signed-off-by: Frank Lichtenheld Acked-by: Arne Schwabe Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1611 Message-Id: <20260808133204.6139-1-gert@greenie.muc.de> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg38233.html Signed-off-by: Gert Doering --- diff --git a/src/openvpn/buffer.c b/src/openvpn/buffer.c index 5f2b2338e..922238df1 100644 --- a/src/openvpn/buffer.c +++ b/src/openvpn/buffer.c @@ -594,6 +594,7 @@ skip_leading_whitespace(const char *str) return str; } +#ifdef _WIN32 /* * like buf_null_terminate, but operate on strings */ @@ -610,6 +611,7 @@ string_null_terminate(char *str, int len, int capacity) *(str + len - 1) = '\0'; } } +#endif /* * Remove trailing \r and \n chars. diff --git a/src/openvpn/buffer.h b/src/openvpn/buffer.h index 1db9367e6..797bd0861 100644 --- a/src/openvpn/buffer.h +++ b/src/openvpn/buffer.h @@ -470,7 +470,9 @@ void rm_trailing_chars(char *str, const char *what_to_delete); const char *skip_leading_whitespace(const char *str); +#ifdef _WIN32 void string_null_terminate(char *str, int len, int capacity); +#endif /** * Write buffer contents to file. diff --git a/src/openvpn/error.c b/src/openvpn/error.c index 2900352b0..26d4c7c90 100644 --- a/src/openvpn/error.c +++ b/src/openvpn/error.c @@ -84,18 +84,20 @@ static char *pgmname_syslog; /* GLOBAL */ /* If non-null, messages should be written here (used for debugging only) */ static FILE *msgfp; /* GLOBAL */ -/* If true, we forked from main OpenVPN process */ -static bool forked; /* GLOBAL */ - /* our default output targets */ static FILE *default_out; /* GLOBAL */ static FILE *default_err; /* GLOBAL */ +/* If true, we forked from main OpenVPN process */ +static bool forked; /* GLOBAL */ + +#if PORT_SHARE void msg_forked(void) { forked = true; } +#endif bool set_debug_level(const int level, const unsigned int flags) diff --git a/src/openvpn/error.h b/src/openvpn/error.h index 3b742d79c..45826a2ce 100644 --- a/src/openvpn/error.h +++ b/src/openvpn/error.h @@ -260,8 +260,10 @@ msg_test(msglvl_t flags) return check_debug_level(flags) && dont_mute(flags); } +#if PORT_SHARE /* Call if we forked */ void msg_forked(void); +#endif /* syslog output */ @@ -393,12 +395,14 @@ ignore_sys_error(const int err, bool crt_error) return false; } +#if defined(ENABLE_CRYPTO_OPENSSL) /** Convert fatal errors to nonfatal, don't touch other errors */ static inline msglvl_t nonfatal(const msglvl_t err) { return (err & M_FATAL) ? (err ^ M_FATAL) | M_NONFATAL : err; } +#endif static inline int openvpn_errno_maybe_crt(bool *crt_error) diff --git a/src/openvpn/socket.c b/src/openvpn/socket.c index 8bcc332d1..0f66ad513 100644 --- a/src/openvpn/socket.c +++ b/src/openvpn/socket.c @@ -2961,6 +2961,8 @@ socket_set(struct link_socket *s, struct event_set *es, unsigned int rwflags, vo return rwflags; } +#if UNIX_SOCK_SUPPORT + void sd_close(socket_descriptor_t *sd) { @@ -2971,8 +2973,6 @@ sd_close(socket_descriptor_t *sd) } } -#if UNIX_SOCK_SUPPORT - /* * code for unix domain sockets */ diff --git a/src/openvpn/socket.h b/src/openvpn/socket.h index b490610e9..1a532e14a 100644 --- a/src/openvpn/socket.h +++ b/src/openvpn/socket.h @@ -366,7 +366,9 @@ void do_preresolve(struct context *c); void link_socket_close(struct link_socket *sock); +#ifdef ENABLE_MANAGEMENT void sd_close(socket_descriptor_t *sd); +#endif void bad_address_length(int actual, int expected); diff --git a/src/openvpn/socket_util.h b/src/openvpn/socket_util.h index 13deeaac2..13f596219 100644 --- a/src/openvpn/socket_util.h +++ b/src/openvpn/socket_util.h @@ -250,6 +250,7 @@ addr_defined(const struct openvpn_sockaddr *addr) } } +#ifdef TARGET_ANDROID static inline bool addr_local(const struct sockaddr *addr) { @@ -269,12 +270,12 @@ addr_local(const struct sockaddr *addr) return false; } } +#endif - +#if ENABLE_IP_PKTINFO static inline bool addr_defined_ipi(const struct link_socket_actual *lsa) { -#if ENABLE_IP_PKTINFO if (!lsa) { return 0; @@ -296,11 +297,9 @@ addr_defined_ipi(const struct link_socket_actual *lsa) default: return 0; } -#else /* if ENABLE_IP_PKTINFO */ - ASSERT(0); -#endif return false; } +#endif /* * Overhead added to packets by various protocols. diff --git a/src/openvpn/ssl_openssl.c b/src/openvpn/ssl_openssl.c index 32b13dbb7..e4b760ead 100644 --- a/src/openvpn/ssl_openssl.c +++ b/src/openvpn/ssl_openssl.c @@ -436,6 +436,7 @@ tls_ctx_restrict_ciphers(struct tls_root_ctx *ctx, const char *ciphers) } } +#ifdef TLS1_3_VERSION static void convert_tls13_list_to_openssl(char *openssl_ciphers, size_t len, const char *ciphers) { @@ -460,6 +461,7 @@ convert_tls13_list_to_openssl(char *openssl_ciphers, size_t len, const char *cip } } } +#endif void tls_ctx_restrict_ciphers_tls13(struct tls_root_ctx *ctx, const char *ciphers) diff --git a/tests/unit_tests/openvpn/test_pkcs11.c b/tests/unit_tests/openvpn/test_pkcs11.c index 8b6e5949b..042bd8baa 100644 --- a/tests/unit_tests/openvpn/test_pkcs11.c +++ b/tests/unit_tests/openvpn/test_pkcs11.c @@ -45,6 +45,7 @@ struct management *management; /* global */ +#if defined(ENABLE_CRYPTO_OPENSSL) /* replacement for crypto_print_openssl_errors() */ void crypto_print_openssl_errors(const unsigned int flags) @@ -55,6 +56,7 @@ crypto_print_openssl_errors(const unsigned int flags) msg(flags, "OpenSSL error %lu: %s", e, ERR_error_string(e, NULL)); } } +#endif /* stubs for some unused functions instead of pulling in too many dependencies */ int