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. Signed-off-by: Thomas Monjalon <thomas.monjalon@6wind.com> Acked-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
This commit is contained in:
parent
f9a08f6502
commit
894f5cc441
@ -61,9 +61,9 @@ test_macros(int __rte_unused unused_parm)
|
||||
|
||||
RTE_SET_USED(unused);
|
||||
|
||||
if (RTE_PTR_ADD(SMALLER, PTR_DIFF) != BIGGER)
|
||||
if ((uintptr_t)RTE_PTR_ADD(SMALLER, PTR_DIFF) != BIGGER)
|
||||
FAIL_MACRO(RTE_PTR_ADD);
|
||||
if (RTE_PTR_SUB(BIGGER, PTR_DIFF) != SMALLER)
|
||||
if ((uintptr_t)RTE_PTR_SUB(BIGGER, PTR_DIFF) != SMALLER)
|
||||
FAIL_MACRO(RTE_PTR_SUB);
|
||||
if (RTE_PTR_DIFF(BIGGER, SMALLER) != PTR_DIFF)
|
||||
FAIL_MACRO(RTE_PTR_DIFF);
|
||||
|
@ -69,12 +69,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
|
||||
@ -130,7 +130,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
|
||||
|
Loading…
Reference in New Issue
Block a user