rsys

Basic data structures and low-level features
git clone git://git.meso-star.fr/rsys.git
Log | Files | Refs | README | LICENSE

commit d75414c9ca0ab32e7276ee16673d4bc904a5f335
parent bb797817c889815b19b12bd05f9f8a819ec7053e
Author: vaplv <vaplv@free.fr>
Date:   Sun, 26 Oct 2014 14:09:04 +0100

Fix an issue in the MEM_AREA_OVERLAP macro

Diffstat:
Msrc/rsys.h | 9++++-----
Msrc/test_mem_allocator.c | 7+++++++
2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/rsys.h b/src/rsys.h @@ -235,11 +235,10 @@ typedef int res_T; #define OFFSET_PTR(Ptr, Offset) (void*)((uintptr_t)(Ptr) + (Offset)) -#define MEM_AREA_OVERLAP( A, SzA, B, SzB ) \ - (((uintptr_t)(A) >= (uintptr_t)(B) && \ - (uintptr_t)(A) < ((uintptr_t)(B) + (SzB))) || \ - (((uintptr_t)(A) + (SzA)) >= (uintptr_t)(B) && \ - ((uintptr_t)(A) + (SzA)) < ((uintptr_t)(B) + (SzB)))) +#define MEM_AREA_OVERLAP(A, SzA, B, SzB) \ + ((uintptr_t)(A) < (uintptr_t)(B) \ + ? (uintptr_t)(B) < ((uintptr_t)(A) + (SzA)) \ + : (uintptr_t)(A) < ((uintptr_t)(B) + (SzB))) #ifdef __cplusplus #define BEGIN_DECLS extern "C" { diff --git a/src/test_mem_allocator.c b/src/test_mem_allocator.c @@ -144,6 +144,7 @@ int main(int argc, char** argv) { struct mem_allocator allocator; + int mem[8]; (void)argc; (void)argv; @@ -159,6 +160,12 @@ main(int argc, char** argv) test_allocator(&allocator); mem_shutdown_proxy_allocator(&allocator); + CHECK(MEM_AREA_OVERLAP(mem, sizeof(int[2]), mem + 2, sizeof(int[6])), 0); + CHECK(MEM_AREA_OVERLAP(mem + 4, sizeof(int[4]), mem, sizeof(int[4])), 0); + CHECK(MEM_AREA_OVERLAP(mem, sizeof(int[2]), mem + 1, sizeof(int[7])), 1); + CHECK(MEM_AREA_OVERLAP(mem + 7, sizeof(int[1]), mem, sizeof(int[8])), 1); + + CHECK(MEM_ALLOCATED_SIZE(&mem_default_allocator), 0); return 0;