eal: fix type of pointer arithmetic result
PATCH 1/1 eal: fix type of pointer arithmetic result
Adding or subtracting a value to a pointer makes a new pointer of unknown type.
So typeof() is replaced by (void*) in RTE_PTR_ADD() and RTE_PTR_SUB().
But RTE_PTR_ALIGN_* macros have in their explicit API to return a pointer of the same type. Since RTE_PTR_ALIGN_CEIL is based on RTE_PTR_ADD, a typeof() is added to keep the original behaviour.
--- lib/librte_eal/common/include/rte_common.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
lib/librte_eal/common/include/rte_common.h +3 -3
@@ -70,12 +70,12 @@ extern "C" {/** * add a byte-value offset from a pointer */ -#define RTE_PTR_ADD (ptr, x) ((typeof(ptr))((uintptr_t)ptr + (x))) +#define RTE_PTR_ADD (ptr, x) ((void*)((uintptr_t)ptr + (x)))/** * subtract a byte-value offset from a pointer */ -#define RTE_PTR_SUB (ptr, x) ((typeof(ptr))((uintptr_t)ptr - (x))) +#define RTE_PTR_SUB (ptr, x) ((void*)((uintptr_t)ptr - (x)))/** * get the difference between two pointer values, i.e. how far apart
@@ -131,7 +131,7 @@ rte_align_floor_int(uintptr_t ptr, uintptr_t align)* must be a power-of-two value. */ #define RTE_PTR_ALIGN_CEIL (ptr, align) \ - RTE_PTR_ALIGN_FLOOR(RTE_PTR_ADD(ptr, align - 1), align) + RTE_PTR_ALIGN_FLOOR((typeof(ptr))RTE_PTR_ADD(ptr, align - 1), align)/** * Macro to align a value to a given power-of-two. The resultant value
Signature · 1 line
1.7.10.4
Adrien Mazarguil
Acked-byQuoted 4 lines · Thomas Monjalon
Adding or subtracting a value to a pointer makes a new pointer of unknown type.
Sotypeof()is replaced by (void*) inRTE_PTR_ADD()andRTE_PTR_SUB().
Quoted 8 lines
But RTE_PTR_ALIGN_* macros have in their explicit API to return a pointer of the same type. Since
RTE_PTR_ALIGN_CEILis based onRTE_PTR_ADD, atypeof()is added to keep the original behaviour.Signed-off-by Thomas Monjalon <[email protected]>--- lib/librte_eal/common/include/rte_common.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
Signature · 2 lines
Adrien Mazarguil 6WIND
26/07/2013 14:12, Adrien Mazarguil :
Quoted 9 lines · Thomas Monjalon
Quoted 8 lines
Adding or subtracting a value to a pointer makes a new pointer of unknown type.
Sotypeof()is replaced by (void*) inRTE_PTR_ADD()andRTE_PTR_SUB().But RTE_PTR_ALIGN_* macros have in their explicit API to return a pointer of the same type. Since
RTE_PTR_ALIGN_CEILis based onRTE_PTR_ADD, atypeof()is added to keep the original behaviour.
Quoted 7 lines
Quoted 5 lines
Signed-off-by Thomas Monjalon <[email protected]>---
lib/librte_eal/common/include/rte_common.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)Acked-by Adrien Mazarguil <[email protected]>
pushed
Signature · 1 line
Thomas