[Openvpn-devel,v1] vlan: Avoid sign conversion warnings

Message ID 20261130173652.30889-1-gert@greenie.muc.de
State New
Headers
Series [Openvpn-devel,v1] vlan: Avoid sign conversion warnings |

Commit Message

Gert Doering Nov. 30, 2026, 5:36 p.m. UTC
  From: Frank Lichtenheld <frank@lichtenheld.com>

Since vid is limited by OPENVPN_8021Q_MASK_VID these
casts are always safe. They are required since we
use -1 for error reporting.

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

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

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

Patch

diff --git a/src/openvpn/vlan.c b/src/openvpn/vlan.c
index d44dac1..02a9bbe 100644
--- a/src/openvpn/vlan.c
+++ b/src/openvpn/vlan.c
@@ -56,11 +56,6 @@ 
         (hdr->pcp_cfi_vid & ~OPENVPN_8021Q_MASK_VID) | (htons(vid) & OPENVPN_8021Q_MASK_VID);
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-conversion"
-#endif
-
 /*
  * vlan_decapsulate - remove 802.1q header and return VID
  *
@@ -110,7 +105,7 @@ 
         msg(D_VLAN_DEBUG, "assuming pvid for frame without vlan-tag, pvid: %u (proto/len 0x%04x)",
             c->options.vlan_pvid, ntohs(ethhdr->proto));
 
-        return c->options.vlan_pvid;
+        return (int16_t)c->options.vlan_pvid;
     }
 
     /* tagged frame */
@@ -145,7 +140,7 @@ 
             if (vid == 0)
             {
                 /* return the global VID for priority-tagged frames */
-                return c->options.vlan_pvid;
+                return (int16_t)c->options.vlan_pvid;
             }
 
             /* here we have a proper VLAN tagged frame: perform decapsulation
@@ -167,7 +162,7 @@ 
             /* restore the inner protocol value */
             ethhdr->proto = proto;
 
-            return vid;
+            return (int16_t)vid;
     }
 
 drop:
@@ -175,10 +170,6 @@ 
     return -1;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 /*
  * vlan_encapsulate - add 802.1q header and set the context related VID
  *