summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitya Selivanov <automainint@guattari.tech>2023-09-08 13:39:48 +0200
committerMitya Selivanov <automainint@guattari.tech>2023-09-08 13:39:48 +0200
commit24be37e59ba144a507bb53f07ca2673e0ed444b4 (patch)
treec5acb85e23255022a6c6f8b721620172f9fec870
parent742528d17955425e5b920136eb4e8fc0c6d1bc82 (diff)
downloadkit-24be37e59ba144a507bb53f07ca2673e0ed444b4.zip
win32 fix ptr arith
-rw-r--r--source/kit/allocator.c14
-rw-r--r--source/kit/allocator.h6
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 <stddef.h>
+#include <stdint.h>
#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