From: Thomas Monjalon Date: Fri, 12 Jul 2013 10:54:35 +0000 (+0200) Subject: eal: fix type of pointer arithmetic result X-Git-Tag: spdx-start~10974 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=894f5cc4411e1d853f80af4db6c74c1ec413f992;p=dpdk.git 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 Acked-by: Adrien Mazarguil --- diff --git a/app/test/test_common.c b/app/test/test_common.c index 36feedcc55..12be1f4732 100644 --- a/app/test/test_common.c +++ b/app/test/test_common.c @@ -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); diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h index 0cf328ecd8..b6ea7f0674 100644 --- a/lib/librte_eal/common/include/rte_common.h +++ b/lib/librte_eal/common/include/rte_common.h @@ -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