From d7871914acd2ed77f43344e36e08944524a67d9e Mon Sep 17 00:00:00 2001 From: Amaury Pouly Date: Mon, 16 Jan 2017 00:10:38 +0100 Subject: Fix dangerous casts On Windows 64-bit, the size of long is 32-bit, thus any pointer to long cast is not valid. In any case, one should use intptr_t and ptrdiff_t when casting to integers. This commit attempts to fix all instances reported by GCC. When relevant, I replaced code by the macros PTR_ADD, ALIGN_UP from system.h Change-Id: I2273b0e8465d3c4689824717ed5afa5ed238a2dc --- lib/tlsf/src/tlsf.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lib/tlsf') diff --git a/lib/tlsf/src/tlsf.c b/lib/tlsf/src/tlsf.c index 6866f0c9b0..136c4152c0 100644 --- a/lib/tlsf/src/tlsf.c +++ b/lib/tlsf/src/tlsf.c @@ -54,6 +54,7 @@ #include #include +#include #ifndef TLSF_USE_LOCKS #define TLSF_USE_LOCKS (0) @@ -462,7 +463,7 @@ size_t init_memory_pool(size_t mem_pool_size, void *mem_pool) return -1; } - if (((unsigned long) mem_pool & PTR_MASK)) { + if (((intptr_t) mem_pool & PTR_MASK)) { ERROR_MSG("init_memory_pool (): mem_pool must be aligned to a word\n"); return -1; } @@ -522,7 +523,7 @@ size_t add_new_area(void *area, size_t area_size, void *mem_pool) lb1 = ptr->end; /* Merging the new area with the next physically contigous one */ - if ((unsigned long) ib1 == (unsigned long) lb0 + BHDR_OVERHEAD) { + if ((uintptr_t) ib1 == (uintptr_t) lb0 + BHDR_OVERHEAD) { if (tlsf->area_head == ptr) { tlsf->area_head = ptr->next; ptr = ptr->next; @@ -543,7 +544,7 @@ size_t add_new_area(void *area, size_t area_size, void *mem_pool) /* Merging the new area with the previous physically contigous one */ - if ((unsigned long) lb1->ptr.buffer == (unsigned long) ib0) { + if ((intptr_t) lb1->ptr.buffer == (intptr_t) ib0) { if (tlsf->area_head == ptr) { tlsf->area_head = ptr->next; ptr = ptr->next; -- cgit v1.2.3