Skip to contentSkip to conversation

Change in openvpn[master]: dco_freebsd.c: fix integer warnings

Openvpn-devel In review cron2 (Code Review) 2 participants 6 messages Nov 7, 2025 – Nov 9, 2025 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1762536182000.Ief19ba87b0832baa6530ea8bf039d85115434e3e@...2715...

#1 lore raw

Attention is currently required from: flichtenheld, plaisthos.

Hello plaisthos, flichtenheld,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1361?usp=email

to review the following change.

Change subject: dco_freebsd.c: fix integer warnings
......................................................................

dco_freebsd.c: fix integer warnings

Fix all nvlist_get_number() related warnings by explicitly casting - these are all messages coming from DCO, which we trust in this (nothing will crash if a number is truncated, just "things will not work correctly").

Remove #pragmas.

Change-Id Ief19ba87b0832baa6530ea8bf039d85115434e3e

---
M src/openvpn/dco_freebsd.c

1 file changed, 11 insertions(+), 17 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/61/1361/1

src/openvpn/dco_freebsd.c +11 -17
index 21f0ac0..f2a89ac 100644
@@ -72,11 +72,6 @@
     return (nvl);
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
-
 static bool
 nvlist_to_sockaddr(const nvlist_t *nvl, struct sockaddr_storage *ss)
 {
@@ -93,7 +88,7 @@
         return (false);
     }
 
-    ss->ss_family = nvlist_get_number(nvl, "af");
+    ss->ss_family = (unsigned char)nvlist_get_number(nvl, "af");
 
     switch (ss->ss_family)
     {
@@ -107,7 +102,7 @@
             data = nvlist_get_binary(nvl, "address", &len);
             ASSERT(len == sizeof(in->sin_addr));
             memcpy(&in->sin_addr, data, sizeof(in->sin_addr));
-            in->sin_port = nvlist_get_number(nvl, "port");
+            in->sin_port = (in_port_t)nvlist_get_number(nvl, "port");
             break;
         }
 
@@ -121,11 +116,11 @@
             data = nvlist_get_binary(nvl, "address", &len);
             ASSERT(len == sizeof(in6->sin6_addr));
             memcpy(&in6->sin6_addr, data, sizeof(in6->sin6_addr));
-            in6->sin6_port = nvlist_get_number(nvl, "port");
+            in6->sin6_port = (in_port_t)nvlist_get_number(nvl, "port");
 
             if (nvlist_exists_number(nvl, "scopeid"))
             {
-                in6->sin6_scope_id = nvlist_get_number(nvl, "scopeid");
+                in6->sin6_scope_id = (uint32_t)nvlist_get_number(nvl, "scopeid");
             }
             break;
         }
@@ -614,9 +609,12 @@
         return -EINVAL;
     }
 
-    dco->dco_message_peer_id = nvlist_get_number(nvl, "peerid");
+    /* dco_message_peer_id is signed int, because other parts of the
+     * code treat "-1" as "this is a message not specific to one peer"
+     */
+    dco->dco_message_peer_id = (int)nvlist_get_number(nvl, "peerid");
 
-    type = nvlist_get_number(nvl, "notification");
+    type = (enum ovpn_notif_type)nvlist_get_number(nvl, "notification");
 
     switch (type)
     {
@@ -625,7 +623,7 @@
 
             if (nvlist_exists_number(nvl, "del_reason"))
             {
-                uint32_t reason = nvlist_get_number(nvl, "del_reason");
+                uint32_t reason = (uint32_t)nvlist_get_number(nvl, "del_reason");
                 if (reason == OVPN_DEL_REASON_TIMEOUT)
                 {
                     dco->dco_del_peer_reason = OVPN_DEL_PEER_REASON_EXPIRED;
@@ -869,7 +867,7 @@
     for (size_t i = 0; i < npeers; i++)
     {
         const nvlist_t *peer = nvpeers[i];
-        uint32_t peerid = nvlist_get_number(peer, "peerid");
+        uint32_t peerid = (uint32_t)nvlist_get_number(peer, "peerid");
         const nvlist_t *bytes = nvlist_get_nvlist(peer, "bytes");
 
         /* we can end here in p2mp mode, or in p2p mode via
@@ -890,10 +888,6 @@
     return 0;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 /* get stats for a single peer
  * we can get here for "the peer stats" in p2p client mode, or by
  * being queried for a particular peer in p2mp mode, for --inactive

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1361?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ief19ba87b0832baa6530ea8bf039d85115434e3e
Gerrit-Change-Number: 1361
Gerrit-PatchSet: 1
Gerrit-Owner: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>

#2 lore raw
In reply to a message not in the archive

Attention is currently required from: cron2, plaisthos.

flichtenheld has posted comments on this change by cron2. ( http://gerrit.openvpn.net/c/openvpn/+/1361?usp=email )

Change subject: dco_freebsd.c: fix integer warnings
......................................................................

Patch Set 1: Code-Review+2

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1361?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ief19ba87b0832baa6530ea8bf039d85115434e3e
Gerrit-Change-Number: 1361
Gerrit-PatchSet: 1
Gerrit-Owner: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Comment-Date: Fri, 07 Nov 2025 17:34:56 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes

#3 lore raw

PATCH 1/1 dco_freebsd.c: fix integer warnings

In reply to a message not in the archive

Fix all nvlist_get_number() related warnings by explicitly casting - these are all messages coming from DCO, which we trust in this (nothing will crash if a number is truncated, just "things will not work correctly").

Remove #pragmas.

Change-Id Ief19ba87b0832baa6530ea8bf039d85115434e3e

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1361
---

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

Acked-by according to Gerrit (reflected above):
Frank Lichtenheld <[email protected]...>

src/openvpn/dco_freebsd.c +11 -17
index 21f0ac0..f2a89ac 100644
@@ -72,11 +72,6 @@
     return (nvl);
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
-
 static bool
 nvlist_to_sockaddr(const nvlist_t *nvl, struct sockaddr_storage *ss)
 {
@@ -93,7 +88,7 @@
         return (false);
     }
 
-    ss->ss_family = nvlist_get_number(nvl, "af");
+    ss->ss_family = (unsigned char)nvlist_get_number(nvl, "af");
 
     switch (ss->ss_family)
     {
@@ -107,7 +102,7 @@
             data = nvlist_get_binary(nvl, "address", &len);
             ASSERT(len == sizeof(in->sin_addr));
             memcpy(&in->sin_addr, data, sizeof(in->sin_addr));
-            in->sin_port = nvlist_get_number(nvl, "port");
+            in->sin_port = (in_port_t)nvlist_get_number(nvl, "port");
             break;
         }
 
@@ -121,11 +116,11 @@
             data = nvlist_get_binary(nvl, "address", &len);
             ASSERT(len == sizeof(in6->sin6_addr));
             memcpy(&in6->sin6_addr, data, sizeof(in6->sin6_addr));
-            in6->sin6_port = nvlist_get_number(nvl, "port");
+            in6->sin6_port = (in_port_t)nvlist_get_number(nvl, "port");
 
             if (nvlist_exists_number(nvl, "scopeid"))
             {
-                in6->sin6_scope_id = nvlist_get_number(nvl, "scopeid");
+                in6->sin6_scope_id = (uint32_t)nvlist_get_number(nvl, "scopeid");
             }
             break;
         }
@@ -614,9 +609,12 @@
         return -EINVAL;
     }
 
-    dco->dco_message_peer_id = nvlist_get_number(nvl, "peerid");
+    /* dco_message_peer_id is signed int, because other parts of the
+     * code treat "-1" as "this is a message not specific to one peer"
+     */
+    dco->dco_message_peer_id = (int)nvlist_get_number(nvl, "peerid");
 
-    type = nvlist_get_number(nvl, "notification");
+    type = (enum ovpn_notif_type)nvlist_get_number(nvl, "notification");
 
     switch (type)
     {
@@ -625,7 +623,7 @@
 
             if (nvlist_exists_number(nvl, "del_reason"))
             {
-                uint32_t reason = nvlist_get_number(nvl, "del_reason");
+                uint32_t reason = (uint32_t)nvlist_get_number(nvl, "del_reason");
                 if (reason == OVPN_DEL_REASON_TIMEOUT)
                 {
                     dco->dco_del_peer_reason = OVPN_DEL_PEER_REASON_EXPIRED;
@@ -869,7 +867,7 @@
     for (size_t i = 0; i < npeers; i++)
     {
         const nvlist_t *peer = nvpeers[i];
-        uint32_t peerid = nvlist_get_number(peer, "peerid");
+        uint32_t peerid = (uint32_t)nvlist_get_number(peer, "peerid");
         const nvlist_t *bytes = nvlist_get_nvlist(peer, "bytes");
 
         /* we can end here in p2mp mode, or in p2p mode via
@@ -890,10 +888,6 @@
     return 0;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 /* get stats for a single peer
  * we can get here for "the peer stats" in p2p client mode, or by
  * being queried for a particular peer in p2mp mode, for --inactive
#4 lore raw

[Openvpn-devel] [PATCH applied] Re: dco_freebsd.c: fix integer warnings

Thanks for the review. Re-Tested on FreeBSD 14.3, no other platforms affected.

(... and with that ends my "write my own code" spree, and back to reviewing and complaining about other people's code... ;-) )

Patch has been applied to the master branch.

commit 7e0b68aeeaebeed71b902299c436371ebc83170e

Author: Gert Doering
Date:   Fri Nov 7 18:48:05 2025 +0100
     dco_freebsd.c: fix integer warnings

     Signed-off-by: Gert Doering <[email protected]...>
     Acked-by: Frank Lichtenheld <[email protected]...>
     Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1361
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg34256.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#5 lore raw
In reply to a message not in the archive

Hello flichtenheld, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1361?usp=email

to look at the new patch set (#2).

The following approvals got outdated and were removed:
Code-Review+2 by flichtenheld

Change subject: dco_freebsd.c: fix integer warnings
......................................................................

dco_freebsd.c: fix integer warnings

Fix all nvlist_get_number() related warnings by explicitly casting - these are all messages coming from DCO, which we trust in this (nothing will crash if a number is truncated, just "things will not work correctly").

Remove #pragmas.

Change-Id Ief19ba87b0832baa6530ea8bf039d85115434e3e

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1361
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg34256.html

---
M src/openvpn/dco_freebsd.c

1 file changed, 11 insertions(+), 17 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/61/1361/2

src/openvpn/dco_freebsd.c +11 -17
index 21f0ac0..f2a89ac 100644
@@ -72,11 +72,6 @@
     return (nvl);
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
-
 static bool
 nvlist_to_sockaddr(const nvlist_t *nvl, struct sockaddr_storage *ss)
 {
@@ -93,7 +88,7 @@
         return (false);
     }
 
-    ss->ss_family = nvlist_get_number(nvl, "af");
+    ss->ss_family = (unsigned char)nvlist_get_number(nvl, "af");
 
     switch (ss->ss_family)
     {
@@ -107,7 +102,7 @@
             data = nvlist_get_binary(nvl, "address", &len);
             ASSERT(len == sizeof(in->sin_addr));
             memcpy(&in->sin_addr, data, sizeof(in->sin_addr));
-            in->sin_port = nvlist_get_number(nvl, "port");
+            in->sin_port = (in_port_t)nvlist_get_number(nvl, "port");
             break;
         }
 
@@ -121,11 +116,11 @@
             data = nvlist_get_binary(nvl, "address", &len);
             ASSERT(len == sizeof(in6->sin6_addr));
             memcpy(&in6->sin6_addr, data, sizeof(in6->sin6_addr));
-            in6->sin6_port = nvlist_get_number(nvl, "port");
+            in6->sin6_port = (in_port_t)nvlist_get_number(nvl, "port");
 
             if (nvlist_exists_number(nvl, "scopeid"))
             {
-                in6->sin6_scope_id = nvlist_get_number(nvl, "scopeid");
+                in6->sin6_scope_id = (uint32_t)nvlist_get_number(nvl, "scopeid");
             }
             break;
         }
@@ -614,9 +609,12 @@
         return -EINVAL;
     }
 
-    dco->dco_message_peer_id = nvlist_get_number(nvl, "peerid");
+    /* dco_message_peer_id is signed int, because other parts of the
+     * code treat "-1" as "this is a message not specific to one peer"
+     */
+    dco->dco_message_peer_id = (int)nvlist_get_number(nvl, "peerid");
 
-    type = nvlist_get_number(nvl, "notification");
+    type = (enum ovpn_notif_type)nvlist_get_number(nvl, "notification");
 
     switch (type)
     {
@@ -625,7 +623,7 @@
 
             if (nvlist_exists_number(nvl, "del_reason"))
             {
-                uint32_t reason = nvlist_get_number(nvl, "del_reason");
+                uint32_t reason = (uint32_t)nvlist_get_number(nvl, "del_reason");
                 if (reason == OVPN_DEL_REASON_TIMEOUT)
                 {
                     dco->dco_del_peer_reason = OVPN_DEL_PEER_REASON_EXPIRED;
@@ -869,7 +867,7 @@
     for (size_t i = 0; i < npeers; i++)
     {
         const nvlist_t *peer = nvpeers[i];
-        uint32_t peerid = nvlist_get_number(peer, "peerid");
+        uint32_t peerid = (uint32_t)nvlist_get_number(peer, "peerid");
         const nvlist_t *bytes = nvlist_get_nvlist(peer, "bytes");
 
         /* we can end here in p2mp mode, or in p2p mode via
@@ -890,10 +888,6 @@
     return 0;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 /* get stats for a single peer
  * we can get here for "the peer stats" in p2p client mode, or by
  * being queried for a particular peer in p2mp mode, for --inactive

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1361?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ief19ba87b0832baa6530ea8bf039d85115434e3e
Gerrit-Change-Number: 1361
Gerrit-PatchSet: 2
Gerrit-Owner: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>

#6 lore raw
In reply to a message not in the archive

cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/1361?usp=email )

Change subject: dco_freebsd.c: fix integer warnings
......................................................................

dco_freebsd.c: fix integer warnings

Fix all nvlist_get_number() related warnings by explicitly casting - these are all messages coming from DCO, which we trust in this (nothing will crash if a number is truncated, just "things will not work correctly").

Remove #pragmas.

Change-Id Ief19ba87b0832baa6530ea8bf039d85115434e3e

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1361
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg34256.html

---
M src/openvpn/dco_freebsd.c

1 file changed, 11 insertions(+), 17 deletions(-)
src/openvpn/dco_freebsd.c +11 -17
index 21f0ac0..f2a89ac 100644
@@ -72,11 +72,6 @@
     return (nvl);
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
-
 static bool
 nvlist_to_sockaddr(const nvlist_t *nvl, struct sockaddr_storage *ss)
 {
@@ -93,7 +88,7 @@
         return (false);
     }
 
-    ss->ss_family = nvlist_get_number(nvl, "af");
+    ss->ss_family = (unsigned char)nvlist_get_number(nvl, "af");
 
     switch (ss->ss_family)
     {
@@ -107,7 +102,7 @@
             data = nvlist_get_binary(nvl, "address", &len);
             ASSERT(len == sizeof(in->sin_addr));
             memcpy(&in->sin_addr, data, sizeof(in->sin_addr));
-            in->sin_port = nvlist_get_number(nvl, "port");
+            in->sin_port = (in_port_t)nvlist_get_number(nvl, "port");
             break;
         }
 
@@ -121,11 +116,11 @@
             data = nvlist_get_binary(nvl, "address", &len);
             ASSERT(len == sizeof(in6->sin6_addr));
             memcpy(&in6->sin6_addr, data, sizeof(in6->sin6_addr));
-            in6->sin6_port = nvlist_get_number(nvl, "port");
+            in6->sin6_port = (in_port_t)nvlist_get_number(nvl, "port");
 
             if (nvlist_exists_number(nvl, "scopeid"))
             {
-                in6->sin6_scope_id = nvlist_get_number(nvl, "scopeid");
+                in6->sin6_scope_id = (uint32_t)nvlist_get_number(nvl, "scopeid");
             }
             break;
         }
@@ -614,9 +609,12 @@
         return -EINVAL;
     }
 
-    dco->dco_message_peer_id = nvlist_get_number(nvl, "peerid");
+    /* dco_message_peer_id is signed int, because other parts of the
+     * code treat "-1" as "this is a message not specific to one peer"
+     */
+    dco->dco_message_peer_id = (int)nvlist_get_number(nvl, "peerid");
 
-    type = nvlist_get_number(nvl, "notification");
+    type = (enum ovpn_notif_type)nvlist_get_number(nvl, "notification");
 
     switch (type)
     {
@@ -625,7 +623,7 @@
 
             if (nvlist_exists_number(nvl, "del_reason"))
             {
-                uint32_t reason = nvlist_get_number(nvl, "del_reason");
+                uint32_t reason = (uint32_t)nvlist_get_number(nvl, "del_reason");
                 if (reason == OVPN_DEL_REASON_TIMEOUT)
                 {
                     dco->dco_del_peer_reason = OVPN_DEL_PEER_REASON_EXPIRED;
@@ -869,7 +867,7 @@
     for (size_t i = 0; i < npeers; i++)
     {
         const nvlist_t *peer = nvpeers[i];
-        uint32_t peerid = nvlist_get_number(peer, "peerid");
+        uint32_t peerid = (uint32_t)nvlist_get_number(peer, "peerid");
         const nvlist_t *bytes = nvlist_get_nvlist(peer, "bytes");
 
         /* we can end here in p2mp mode, or in p2p mode via
@@ -890,10 +888,6 @@
     return 0;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 /* get stats for a single peer
  * we can get here for "the peer stats" in p2p client mode, or by
  * being queried for a particular peer in p2mp mode, for --inactive

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1361?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ief19ba87b0832baa6530ea8bf039d85115434e3e
Gerrit-Change-Number: 1361
Gerrit-PatchSet: 2
Gerrit-Owner: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>