Skip to content

Commit

Permalink
Fix: Casting malloc
Browse files Browse the repository at this point in the history
Closes #193

Co-authored-by: Yuri Victorovich <271906+yurivict@users.noreply.github.com>
  • Loading branch information
ashvardanian and yurivict committed Nov 9, 2024
1 parent 35ed3f9 commit 5d531b3
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions include/stringzilla/stringzilla.h
Original file line number Diff line number Diff line change
Expand Up @@ -1805,12 +1805,22 @@ SZ_INTERNAL void _sz_locate_needle_anomalies(sz_cptr_t start, sz_size_t length,
#if !SZ_AVOID_LIBC
#include <stdio.h> // `fprintf`
#include <stdlib.h> // `malloc`, `EXIT_FAILURE`

SZ_PUBLIC void *_sz_memory_allocate_default(sz_size_t length, void *handle) {
sz_unused(handle);
return malloc(length);
}
SZ_PUBLIC void _sz_memory_free_default(sz_ptr_t start, sz_size_t length, void *handle) {
sz_unused(handle && length);
free(start);
}

#endif

SZ_PUBLIC void sz_memory_allocator_init_default(sz_memory_allocator_t *alloc) {
#if !SZ_AVOID_LIBC
alloc->allocate = (sz_memory_allocate_t)malloc;
alloc->free = (sz_memory_free_t)free;
alloc->allocate = (sz_memory_allocate_t)_sz_memory_allocate_default;
alloc->free = (sz_memory_free_t)_sz_memory_free_default;
#else
alloc->allocate = (sz_memory_allocate_t)SZ_NULL;
alloc->free = (sz_memory_free_t)SZ_NULL;
Expand Down

0 comments on commit 5d531b3

Please sign in to comment.