Files
Toy/source/memory.c
Kayne Ruse 1937d727bb Working on refactoring, read more
The main program segfaults, but right now I'm working on the tests, mainly.
2022-08-29 10:21:25 +10:00

25 lines
461 B
C

#include "memory.h"
#include "console_colors.h"
#include <stdio.h>
#include <stdlib.h>
void* reallocate(void* pointer, size_t oldSize, size_t newSize) {
if (newSize == 0) {
free(pointer);
return NULL;
}
void* mem = realloc(pointer, newSize);
if (mem == NULL) {
fprintf(stderr, ERROR "[internal]Memory allocation error (requested %d for %ld, replacing %d)\n" ERROR, (int)newSize, (long int)pointer, (int)oldSize);
exit(-1);
}
return mem;
}