]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: cast {,CONST_}PTR_OFFSET's offset argument to size_t
authorJosef 'Jeff' Sipek <jeff.sipek@dovecot.fi>
Mon, 22 Jan 2018 20:58:51 +0000 (15:58 -0500)
committerJosef 'Jeff' Sipek <jeff.sipek@dovecot.fi>
Mon, 22 Jan 2018 20:58:51 +0000 (15:58 -0500)
This fixes build on 32-bit systems where the addition may cause integer
promotion to an integer type larger than uintptr_t.

gcc 6.3.0 warning:

file-cache.c: In function 'file_cache_write':
macros.h:25:3: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
  ((void *) (((uintptr_t) (ptr)) + (offset)))

src/lib/macros.h

index 8c4e0df489b60407add54be85adf0268928dfe9d..22e4ef8ef0bd96bbf067cfc492938bdb6a963430 100644 (file)
@@ -22,9 +22,9 @@
        (((size) + MEM_ALIGN_SIZE-1) & ~((size_t) MEM_ALIGN_SIZE-1))
 
 #define PTR_OFFSET(ptr, offset) \
-       ((void *) (((uintptr_t) (ptr)) + (offset)))
+       ((void *) (((uintptr_t) (ptr)) + ((size_t) (offset))))
 #define CONST_PTR_OFFSET(ptr, offset) \
-       ((const void *) (((uintptr_t) (ptr)) + (offset)))
+       ((const void *) (((uintptr_t) (ptr)) + ((size_t) (offset))))
 
 #define container_of(ptr, type, name) \
        (type *)((uintptr_t)(ptr) - (uintptr_t)offsetof(type, name) + \