[ovs-dev] [PATCH 1/2] packet: proper return type for vlan_tci_to_pcp()

Shu Shen shu.shen at gmail.com
Thu Feb 2 23:15:27 UTC 2017


The return type of vlan_tci_to_pcp() was int where it's expected to be
uint8_t and causing implicit truncation when the function is used.

On some platforms such as macOS, where PRIu8 is defined as "hhx" and no
promotion of short to int is done, the compiler might throw out Wformat
message for ds_put_format() calls on the returns value of
vlan_tci_to_pcp().

vlan_tci_to_cfi() is also fixed with uint8_t as return type although the
function is not currently being used anywhere.

Signed-off-by: Shu Shen <shu.shen at gmail.com>
---
 lib/packets.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/packets.h b/lib/packets.h
index c4d3799..2cf5419 100644
--- a/lib/packets.h
+++ b/lib/packets.h
@@ -421,7 +421,7 @@ vlan_tci_to_vid(ovs_be16 vlan_tci)
 
 /* Given the vlan_tci field from an 802.1Q header, in network byte order,
  * returns the priority code point (PCP) in host byte order. */
-static inline int
+static inline uint8_t
 vlan_tci_to_pcp(ovs_be16 vlan_tci)
 {
     return (ntohs(vlan_tci) & VLAN_PCP_MASK) >> VLAN_PCP_SHIFT;
@@ -429,7 +429,7 @@ vlan_tci_to_pcp(ovs_be16 vlan_tci)
 
 /* Given the vlan_tci field from an 802.1Q header, in network byte order,
  * returns the Canonical Format Indicator (CFI). */
-static inline int
+static inline uint8_t
 vlan_tci_to_cfi(ovs_be16 vlan_tci)
 {
     return (vlan_tci & htons(VLAN_CFI)) != 0;
-- 
1.9.1



More information about the dev mailing list