summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Monjalon <thomas.monjalon@6wind.com>2013-07-12 14:54:35 +0200
committerThomas Monjalon <thomas.monjalon@6wind.com>2013-09-17 14:16:11 +0200
commite08cc17543a64dd5683c1d371dd8bae18b5d1530 (patch)
treef6b7f4eb50b441bcc423207016cd123462ec72d1
parent02f061016768aa2d7d878f0ccb8de68c96b431f7 (diff)
downloaddpdk-e08cc17543a64dd5683c1d371dd8bae18b5d1530.zip
dpdk-e08cc17543a64dd5683c1d371dd8bae18b5d1530.tar.gz
dpdk-e08cc17543a64dd5683c1d371dd8bae18b5d1530.tar.xz
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>
-rw-r--r--app/test/test_common.c4
-rw-r--r--lib/librte_eal/common/include/rte_common.h6
2 files changed, 5 insertions, 5 deletions
diff --git a/app/test/test_common.c b/app/test/test_common.c
index a5fab84..a59e36b 100644
--- a/app/test/test_common.c
+++ b/app/test/test_common.c
@@ -62,9 +62,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 0ad06ec..5c6ef6c 100644
--- a/lib/librte_eal/common/include/rte_common.h
+++ b/lib/librte_eal/common/include/rte_common.h
@@ -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