[Openvpn-devel,v3] dhcp: Fix conversion warnings

Message ID 20251006210127.28679-1-gert@greenie.muc.de
State New
Headers show
Series [Openvpn-devel,v3] dhcp: Fix conversion warnings | expand

Commit Message

Gert Doering Oct. 6, 2025, 9:01 p.m. UTC
From: Frank Lichtenheld <frank@lichtenheld.com>

- Use correct type for pointer difference
- Make sure that small sizeof sum is treated as int

Change-Id: Ie0c0fbf4f7f8b379d46b6755c4eff209acc20fef
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1241
---

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

Acked-by according to Gerrit (reflected above):
Gert Doering <gert@greenie.muc.de>

Comments

Gert Doering Oct. 7, 2025, 7:36 a.m. UTC | #1
One learns something new about C every day :-) - had to look up what
an "intptr_t" is ("it's an integer type big enough to hold any pointer
type"), so that's the correct thing for pointer differences as well
(even though it's not really relevant *here*, as we're not talking
about ">4 Gbyte difference, in a 32/64 bit addressing model").

Anyway.  Patch makes sense. BBs are happy.  Not tested beyond a build
test on ubuntu/mingw.

Your patch has been applied to the master branch.

commit d446715c537764076ea8d61233bf37d3bafa7624
Author: Frank Lichtenheld
Date:   Mon Oct 6 23:01:21 2025 +0200

     dhcp: Fix conversion warnings

     Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
     Acked-by: Gert Doering <gert@greenie.muc.de>
     Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1241
     Message-Id: <20251006210127.28679-1-gert@greenie.muc.de>
     URL: https://sourceforge.net/p/openvpn/mailman/message/59243110/
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering

Patch

diff --git a/src/openvpn/dhcp.c b/src/openvpn/dhcp.c
index 38e8d40..850a4b6 100644
--- a/src/openvpn/dhcp.c
+++ b/src/openvpn/dhcp.c
@@ -72,11 +72,6 @@ 
     return -1;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
-
 static in_addr_t
 do_extract(struct dhcp *dhcp, int optlen)
 {
@@ -115,7 +110,7 @@ 
                         const int owlen = len + 2; /* len of data to overwrite */
                         uint8_t *src = dest + owlen;
                         uint8_t *end = p + optlen;
-                        const int movlen = end - src;
+                        const intptr_t movlen = end - src;
                         if (movlen > 0)
                         {
                             memmove(dest, src, movlen);       /* overwrite router option */
@@ -155,7 +150,7 @@ 
     struct dhcp_full *df = (struct dhcp_full *)BPTR(ipbuf);
     const int optlen =
         BLEN(ipbuf)
-        - (sizeof(struct openvpn_iphdr) + sizeof(struct openvpn_udphdr) + sizeof(struct dhcp));
+        - (int)(sizeof(struct openvpn_iphdr) + sizeof(struct openvpn_udphdr) + sizeof(struct dhcp));
 
     if (optlen >= 0 && df->ip.protocol == OPENVPN_IPPROTO_UDP
         && df->udp.source == htons(BOOTPS_PORT) && df->udp.dest == htons(BOOTPC_PORT)
@@ -190,7 +185,3 @@ 
     }
     return 0;
 }
-
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif