Skip to contentSkip to conversation

eal: fix type of pointer arithmetic result

PATCH In review Thomas Monjalon 2 participants 3 messages Jul 26, 2013 2 messages not in the archive

lore
Share & tools
lore
#0 lore raw

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
index 96aeeee..d2e096d 100644
@@ -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

A message that is not in the archive (sent off-list or not yet received): 1374838440-21429-1-git-send-email-thomas.monjalon-pdR9zngts4EAvxtiuMwx3w@public.gmane.org

#2 lore raw
Quoted 4 lines · Thomas Monjalon

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().

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_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(-)
Signature · 2 lines
Adrien Mazarguil
6WIND

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw

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.
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.

Quoted 7 lines
Quoted 5 lines

---

 lib/librte_eal/common/include/rte_common.h |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

pushed

Signature · 1 line
Thomas