diff mbox

[dpdk-dev,v2] test-pmd: Fix pointer aliasing error

Message ID 1417663711-19576-1-git-send-email-michael.qiu@intel.com (mailing list archive)
State Superseded, archived
Headers show

Commit Message

Michael Qiu Dec. 4, 2014, 3:28 a.m. UTC
app/test-pmd/csumonly.c: In function ‘get_psd_sum’:
build/include/rte_ip.h:161: error: dereferencing pointer ‘u16’
        does break strict-aliasing rules
build/include/rte_ip.h:157: note: initialized from here
        ...

The root cause is that, compile enable strict aliasing by default,
while in function rte_raw_cksum() try to convert 'const char *'
to 'const uint16_t *'.

This patch is one workaround fix.

Signed-off-by: Michael Qiu <michael.qiu@intel.com>
---
 lib/librte_net/rte_ip.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Ananyev, Konstantin Dec. 4, 2014, 12:54 p.m. UTC | #1
> -----Original Message-----

> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Michael Qiu

> Sent: Thursday, December 04, 2014 3:29 AM

> To: dev@dpdk.org

> Subject: [dpdk-dev] [PATCH v2] test-pmd: Fix pointer aliasing error

> 

> 

> app/test-pmd/csumonly.c: In function ‘get_psd_sum’:

> build/include/rte_ip.h:161: error: dereferencing pointer ‘u16’

>         does break strict-aliasing rules

> build/include/rte_ip.h:157: note: initialized from here

>         ...

> 

> The root cause is that, compile enable strict aliasing by default,

> while in function rte_raw_cksum() try to convert 'const char *'

> to 'const uint16_t *'.

> 

> This patch is one workaround fix.

> 

> Signed-off-by: Michael Qiu <michael.qiu@intel.com>

> ---

>  lib/librte_net/rte_ip.h | 3 ++-

>  1 file changed, 2 insertions(+), 1 deletion(-)

> 

> diff --git a/lib/librte_net/rte_ip.h b/lib/librte_net/rte_ip.h

> index 61e4457..f1c7087 100644

> --- a/lib/librte_net/rte_ip.h

> +++ b/lib/librte_net/rte_ip.h

> @@ -154,7 +154,8 @@ struct ipv4_hdr {

>  static inline uint16_t

>  rte_raw_cksum(const char *buf, size_t len)

>  {

> -	const uint16_t *u16 = (const uint16_t *)buf;

> +	unsigned long ptr = (unsigned long)buf;


I think better use uintptr_t here.
It is specially designed to be long enough to hold pointer value.

> +	const uint16_t *u16 = (const uint16_t *)ptr;

>  	uint32_t sum = 0;

> 

>  	while (len >= (sizeof(*u16) * 4)) {

> --

> 1.9.3
diff mbox

Patch

diff --git a/lib/librte_net/rte_ip.h b/lib/librte_net/rte_ip.h
index 61e4457..f1c7087 100644
--- a/lib/librte_net/rte_ip.h
+++ b/lib/librte_net/rte_ip.h
@@ -154,7 +154,8 @@  struct ipv4_hdr {
 static inline uint16_t
 rte_raw_cksum(const char *buf, size_t len)
 {
-	const uint16_t *u16 = (const uint16_t *)buf;
+	unsigned long ptr = (unsigned long)buf;
+	const uint16_t *u16 = (const uint16_t *)ptr;
 	uint32_t sum = 0;
 
 	while (len >= (sizeof(*u16) * 4)) {