From ac7aa955db4c77bbb169baa5d104a4c128674646 Mon Sep 17 00:00:00 2001 From: Aki Tuomi Date: Sun, 14 Jan 2018 19:21:36 +0200 Subject: [PATCH] lib: Use uintptr_t in PTR_OFFSET and POINTER_CAST Use uintptr_t instead of pointers. Fixes clang 6.0 warning: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension --- src/lib/macros.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/macros.h b/src/lib/macros.h index eec7cd2f02..8c4e0df489 100644 --- a/src/lib/macros.h +++ b/src/lib/macros.h @@ -22,9 +22,9 @@ (((size) + MEM_ALIGN_SIZE-1) & ~((size_t) MEM_ALIGN_SIZE-1)) #define PTR_OFFSET(ptr, offset) \ - ((void *) (((unsigned char *) (ptr)) + (offset))) + ((void *) (((uintptr_t) (ptr)) + (offset))) #define CONST_PTR_OFFSET(ptr, offset) \ - ((const void *) (((const unsigned char *) (ptr)) + (offset))) + ((const void *) (((uintptr_t) (ptr)) + (offset))) #define container_of(ptr, type, name) \ (type *)((uintptr_t)(ptr) - (uintptr_t)offsetof(type, name) + \ @@ -39,7 +39,7 @@ sizeof(size_t) == sizeof(void *) and they're both the largest datatypes that are allowed to be used. so, long long isn't safe with these. */ #define POINTER_CAST(i) \ - ((void *) ((char *) NULL + (i))) + ((void *) (((uintptr_t)NULL) + (i))) #define POINTER_CAST_TO(p, type) \ ((type) ((const char *) (p) - (const char *) NULL))