[Openvpn-devel,v2] ssl_util: Switch get_num_elements to size_t

Message ID 20261116145745.8299-1-gert@greenie.muc.de
State New
Headers
Series [Openvpn-devel,v2] ssl_util: Switch get_num_elements to size_t |

Commit Message

Gert Doering Nov. 16, 2026, 2:57 p.m. UTC
  From: Frank Lichtenheld <frank@lichtenheld.com>

ALLOC_ARRAY already wants size_t.

Change-Id: If79d4356b5da82c2844cd9e8c59a0fc41aeff3c0
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: Razvan Cojocaru <razvanc@mailbox.org>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2199
---

This change was reviewed on Gerrit and approved by at least one
developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2199
This mail reflects revision 2 of this Change.

Acked-by according to Gerrit (reflected above):
Razvan Cojocaru <razvanc@mailbox.org>
  

Comments

Gert Doering Nov. 16, 2026, 5:43 p.m. UTC | #1
Seems to make sense, makes the compiler happy, gets rid of #pragma :-)

Your patch has been applied to the master branch.

commit 7d46ff17248908acf906134ee1e03ded831634a6
Author: Frank Lichtenheld
Date:   Mon Nov 16 15:57:36 2026 +0100

     ssl_util: Switch get_num_elements to size_t

     Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
     Acked-by: Razvan Cojocaru <razvanc@mailbox.org>
     Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2199
     Message-Id: <20261116145745.8299-1-gert@greenie.muc.de>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg41458.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering
  

Patch

diff --git a/src/openvpn/ssl_mbedtls.c b/src/openvpn/ssl_mbedtls.c
index 2d29e60..19a2d48 100644
--- a/src/openvpn/ssl_mbedtls.c
+++ b/src/openvpn/ssl_mbedtls.c
@@ -199,11 +199,6 @@ 
         ciphers);
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-conversion"
-#endif
-
 void
 tls_ctx_restrict_ciphers(struct tls_root_ctx *ctx, const char *ciphers)
 {
@@ -217,7 +212,7 @@ 
     ASSERT(NULL != ctx);
 
     /* Get number of ciphers */
-    int cipher_count = get_num_elements(ciphers, ':');
+    size_t cipher_count = get_num_elements(ciphers, ':');
 
     /* Allocate an array for them */
     ALLOC_ARRAY_CLEAR(ctx->allowed_ciphers, int, cipher_count + 1)
@@ -339,7 +334,7 @@ 
     struct gc_arena gc = gc_new();
 
     /* Get number of groups and allocate an array in ctx */
-    int groups_count = get_num_elements(groups, ':');
+    size_t groups_count = get_num_elements(groups, ':');
     ALLOC_ARRAY_CLEAR(ctx->groups, uint16_t, groups_count + 1)
 
     /* Parse allowed ciphers, getting IDs */
@@ -1188,10 +1183,6 @@ 
     return 1;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 /* **************************************
  *
  * Information functions
diff --git a/src/openvpn/ssl_openssl.c b/src/openvpn/ssl_openssl.c
index 7622d88..30ef383 100644
--- a/src/openvpn/ssl_openssl.c
+++ b/src/openvpn/ssl_openssl.c
@@ -518,11 +518,6 @@ 
 {
     ASSERT(ctx);
 #if OPENSSL_VERSION_NUMBER < 0x30000000L && !defined(ENABLE_CRYPTO_WOLFSSL)
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-conversion"
-#endif
-
     struct gc_arena gc = gc_new();
     /* This method could be as easy as
      *  SSL_CTX_set1_groups_list(ctx->ctx, groups)
@@ -533,7 +528,7 @@ 
      * Also note that the code is wrong in the presence of OpenSSL3 providers.
      */
 
-    int groups_count = get_num_elements(groups, ':');
+    size_t groups_count = get_num_elements(groups, ':');
 
     int *glist;
     /* Allocate an array for them */
@@ -569,9 +564,6 @@ 
     }
     gc_free(&gc);
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
 #else  /* if OPENSSL_VERSION_NUMBER < 0x30000000L */
     if (!SSL_CTX_set1_groups_list(ctx->ctx, groups))
     {
diff --git a/src/openvpn/ssl_util.c b/src/openvpn/ssl_util.c
index 337faed..6c17fe5 100644
--- a/src/openvpn/ssl_util.c
+++ b/src/openvpn/ssl_util.c
@@ -359,14 +359,14 @@ 
     return NULL;
 }
 
-int
+size_t
 get_num_elements(const char *string, char delimiter)
 {
     const size_t string_len = strlen(string);
 
     ASSERT(0 != string_len);
 
-    int element_count = 1;
+    size_t element_count = 1;
     /* Get number of ciphers */
     for (size_t i = 0; i < string_len; i++)
     {
diff --git a/src/openvpn/ssl_util.h b/src/openvpn/ssl_util.h
index 6f9f65b..db5e17c 100644
--- a/src/openvpn/ssl_util.h
+++ b/src/openvpn/ssl_util.h
@@ -125,6 +125,6 @@ 
  * @param delimiter     the delimiter to count, typically ':'
  * @return              occrrences of delimiter + 1
  */
-int get_num_elements(const char *string, char delimiter);
+size_t get_num_elements(const char *string, char delimiter);
 
 #endif /* ifndef SSL_UTIL_H_ */