[Openvpn-devel,v8] init: Avoid sign-compare warnings

Message ID 20260815130856.20431-1-gert@greenie.muc.de
State New
Headers
Series [Openvpn-devel,v8] init: Avoid sign-compare warnings |

Commit Message

Gert Doering Aug. 15, 2026, 1:08 p.m. UTC
  From: Frank Lichtenheld <frank@lichtenheld.com>

- Use BLENZ instead of buf_len where applicable
- Fix some comparisons with ce list length

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

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/+/1562
This mail reflects revision 8 of this Change.

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

Comments

Gert Doering Aug. 15, 2026, 7:56 p.m. UTC | #1
Changes look reasonable, and another few #pragma gone - thanks, Razvan for
reviewing.   Just compile tested ("and BB all green").

Your patch has been applied to the master branch.

commit 6f772b55f5ae4933b115b3e0cdd25e3c6718404c
Author: Frank Lichtenheld
Date:   Sat Aug 15 15:08:49 2026 +0200

     init: Avoid sign-compare warnings

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


--
kind regards,

Gert Doering
  

Patch

diff --git a/src/openvpn/init.c b/src/openvpn/init.c
index caaa769..2196364 100644
--- a/src/openvpn/init.c
+++ b/src/openvpn/init.c
@@ -325,11 +325,6 @@ 
     return l->len;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-compare"
-#endif
-
 static bool
 management_callback_remote_entry_get(void *arg, unsigned int index, char **remote)
 {
@@ -340,7 +335,7 @@ 
     struct connection_list *l = c->options.connection_list;
     bool ret = true;
 
-    if (index < l->len)
+    if (l->len > 0 && index < (unsigned int)l->len)
     {
         struct connection_entry *ce = l->array[index];
         const char *proto = proto2ascii(ce->proto, ce->af, false);
@@ -364,10 +359,6 @@ 
     return ret;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 static bool
 management_callback_remote_cmd(void *arg, const char **p)
 {
@@ -466,7 +457,6 @@ 
 #if defined(__GNUC__) || defined(__clang__)
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wconversion"
-#pragma GCC diagnostic ignored "-Wsign-compare"
 #endif
 
 /*
@@ -638,8 +628,8 @@ 
     } while (!ce_defined);
 
     /* Check if this connection attempt would bring us over the limit */
-    if (c->options.connect_retry_max > 0
-        && c->options.unsuccessful_attempts > (l->len * c->options.connect_retry_max))
+    int max_attempts = l->len * c->options.connect_retry_max;
+    if (max_attempts > 0 && c->options.unsuccessful_attempts > (unsigned int)max_attempts)
     {
         msg(M_FATAL, "All connections have been connect-retry-max (%d) times unsuccessful, exiting",
             c->options.connect_retry_max);
@@ -2176,7 +2166,7 @@ 
 static void
 add_delim_if_non_empty(struct buffer *buf, const char *header)
 {
-    if (buf_len(buf) > strlen(header))
+    if (BLENZ(buf) > strlen(header))
     {
         buf_printf(buf, ", ");
     }
@@ -2264,7 +2254,7 @@ 
         buf_printf(&out, "session-timeout %d", o->session_timeout);
     }
 
-    if (buf_len(&out) > strlen(header))
+    if (BLENZ(&out) > strlen(header))
     {
         msg(D_HANDSHAKE, "%s", BSTR(&out));
     }
@@ -2301,7 +2291,7 @@ 
         }
     }
 
-    if (buf_len(&out) > strlen(header))
+    if (BLENZ(&out) > strlen(header))
     {
         msg(D_HANDSHAKE, "%s", BSTR(&out));
     }