From ea70726b079c7b11526bb1cdab071acf63b5d638 Mon Sep 17 00:00:00 2001 From: Joel Cunningham Date: Tue, 31 Oct 2017 09:41:19 -0500 Subject: [PATCH] Introduce LWIP_PACKED_CAST to fix errors issues with ARMCC ARMCC when using __packed structures will not implicitly convert a pointer to a member of a packed structure to something which does not have __packed. This results in a compiler error and was found with calls to icmp6_param_problem While there is a #pragma pack mode in ARMCC that disables this error, it does require existing ports to switch over their packing mode and perform integration --- src/core/ipv6/ip6.c | 4 ++-- src/include/lwip/arch.h | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/core/ipv6/ip6.c b/src/core/ipv6/ip6.c index 90bf5b0f..48447bd7 100644 --- a/src/core/ipv6/ip6.c +++ b/src/core/ipv6/ip6.c @@ -919,7 +919,7 @@ netif_found: /* The length field of routing option header must be even */ if (rout_hdr->_hlen & 0x1) { /* Discard and send parameter field error */ - icmp6_param_problem(p, ICMP6_PP_FIELD, &rout_hdr->_hlen); + icmp6_param_problem(p, ICMP6_PP_FIELD, LWIP_PACKED_CAST(const void *, &rout_hdr->_hlen)); LWIP_DEBUGF(IP6_DEBUG, ("ip6_input: packet with invalid routing type dropped\n")); pbuf_free(p); IP6_STATS_INC(ip6.drop); @@ -976,7 +976,7 @@ netif_found: /* check payload length is multiple of 8 octets when mbit is set */ if (IP6_FRAG_MBIT(frag_hdr) && (IP6H_PLEN(ip6hdr) & 0x7)) { /* ipv6 payload length is not multiple of 8 octets */ - icmp6_param_problem(p, ICMP6_PP_FIELD, &ip6hdr->_plen); + icmp6_param_problem(p, ICMP6_PP_FIELD, LWIP_PACKED_CAST(const void *, &ip6hdr->_plen)); LWIP_DEBUGF(IP6_DEBUG, ("ip6_input: packet with invalid payload length dropped\n")); pbuf_free(p); IP6_STATS_INC(ip6.drop); diff --git a/src/include/lwip/arch.h b/src/include/lwip/arch.h index 488f9972..dafd500c 100644 --- a/src/include/lwip/arch.h +++ b/src/include/lwip/arch.h @@ -220,6 +220,11 @@ typedef int ssize_t; #define LWIP_PTR_NUMERIC_CAST(target_type, val) LWIP_CONST_CAST(target_type, val) #endif +/** Avoid warnings/errors related to implicitly casting away packed attributes by doing a explicit cast */ +#ifndef LWIP_PACKED_CAST +#define LWIP_PACKED_CAST(target_type, val) LWIP_CONST_CAST(target_type, val) +#endif + /** Allocates a memory buffer of specified size that is of sufficient size to align * its start address using LWIP_MEM_ALIGN. * You can declare your own version here e.g. to enforce alignment without adding -- 2.14.1