]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Use uintptr_t in PTR_OFFSET and POINTER_CAST
authorAki Tuomi <aki.tuomi@dovecot.fi>
Sun, 14 Jan 2018 17:21:36 +0000 (19:21 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 17 Jan 2018 14:52:46 +0000 (16:52 +0200)
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

index eec7cd2f02c3db510b1d1eb295c61d9927db64a5..8c4e0df489b60407add54be85adf0268928dfe9d 100644 (file)
@@ -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))