From 4921c5e94b7acdd152dcffa942a834f253bc0aaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Date: Mon, 1 Nov 2021 21:01:18 +0100 Subject: [PATCH] defs: use intptr types where applicaple Instead of doing pointer arithmetic through actual pointers, cast them to the proper integer types. This is functionally equivalent to the previous code but is clearer for the compiler. Fixes #1018 --- spa/include/spa/utils/defs.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spa/include/spa/utils/defs.h b/spa/include/spa/utils/defs.h index 0234e6f1f..f37216e73 100644 --- a/spa/include/spa/utils/defs.h +++ b/spa/include/spa/utils/defs.h @@ -163,7 +163,7 @@ struct spa_fraction { /** * Return the address (buffer + offset) as pointer of \a type */ -#define SPA_PTROFF(ptr_,offset_,type_) ((type_*)((uint8_t*)(ptr_) + (int)(offset_))) +#define SPA_PTROFF(ptr_,offset_,type_) ((type_*)((uintptr_t)(ptr_) + (ptrdiff_t)(offset_))) #define SPA_PTROFF_ALIGN(ptr_,offset_,alignment_,type_) \ SPA_PTR_ALIGN(SPA_PTROFF(ptr_,offset_,type_),alignment_,type_) @@ -174,9 +174,9 @@ struct spa_fraction { #define SPA_MEMBER(b,o,t) SPA_PTROFF(b,o,t) #define SPA_MEMBER_ALIGN(b,o,a,t) SPA_PTROFF_ALIGN(b,o,a,t) -#define SPA_CONTAINER_OF(p,t,m) (t*)((uint8_t*)p - offsetof (t,m)) +#define SPA_CONTAINER_OF(p,t,m) (t*)((uintptr_t)p - offsetof (t,m)) -#define SPA_PTRDIFF(p1,p2) ((uint8_t*)(p1) - (uint8_t*)(p2)) +#define SPA_PTRDIFF(p1,p2) ((intptr_t)(p1) - (intptr_t)(p2)) #define SPA_PTR_TO_INT(p) ((int) ((intptr_t) (p))) #define SPA_INT_TO_PTR(u) ((void*) ((intptr_t) (u)))