From 24be37e59ba144a507bb53f07ca2673e0ed444b4 Mon Sep 17 00:00:00 2001 From: Mitya Selivanov Date: Fri, 8 Sep 2023 13:39:48 +0200 Subject: win32 fix ptr arith --- source/kit/allocator.c | 14 +++++++------- source/kit/allocator.h | 6 +++++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/source/kit/allocator.c b/source/kit/allocator.c index f39c903..149cddb 100644 --- a/source/kit/allocator.c +++ b/source/kit/allocator.c @@ -43,10 +43,10 @@ static void *kit_allocate_default_(int request, ptrdiff_t size, if (size == previous_size) return pointer; - void *p = NULL; + uint8_t *p = NULL; if (size > 0) { - p = malloc(size); + p = (uint8_t *) malloc(size); if (p != NULL) { if (size > 0 && previous_size > 0) @@ -106,7 +106,7 @@ static void *kit_allocate_from_buffer_(kit_allocator_t *alloc, return NULL; void *p = alloc->data; - alloc->data += size; + alloc->bytes += size; alloc->size -= size; if (request == KIT_ALLOCATE_ZERO) @@ -130,10 +130,10 @@ static void *kit_allocate_from_buffer_(kit_allocator_t *alloc, if (previous_size != 0 && pointer == NULL) return NULL; - if (pointer + previous_size == alloc->data) { + if ((uint8_t *) pointer + previous_size == alloc->data) { if (alloc->size < size - previous_size) return NULL; - alloc->data += size - previous_size; + alloc->bytes += size - previous_size; alloc->size -= size - previous_size; return pointer; } @@ -141,8 +141,8 @@ static void *kit_allocate_from_buffer_(kit_allocator_t *alloc, if (alloc->size < size) return NULL; - void *p = alloc->data; - alloc->data += size; + uint8_t *p = alloc->bytes; + alloc->bytes += size; alloc->size -= size; if (previous_size > 0) diff --git a/source/kit/allocator.h b/source/kit/allocator.h index 340883d..b344d4b 100644 --- a/source/kit/allocator.h +++ b/source/kit/allocator.h @@ -6,6 +6,7 @@ #endif #include +#include #ifdef __cplusplus extern "C" { @@ -29,7 +30,10 @@ enum { typedef struct { int type; ptrdiff_t size; - void *data; + union { + uint8_t *bytes; + void *data; + }; } kit_allocator_t; // Application should implement this function if custom allocator -- cgit v1.2.3