From 9c6b9a1450d6610a37234b016bc1cfb021f30ee8 Mon Sep 17 00:00:00 2001 From: pommicket Date: Sat, 19 Feb 2022 12:01:56 -0500 Subject: full build of tcc with itself - doesn't match gcc :o --- 05/stdlib.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to '05/stdlib.h') diff --git a/05/stdlib.h b/05/stdlib.h index b93d4aa..cbfd0b5 100644 --- a/05/stdlib.h +++ b/05/stdlib.h @@ -73,12 +73,25 @@ void *realloc(void *ptr, size_t size) { free(ptr); return NULL; } +#if 0 + // this (better) implementation doesn't seem to be copying stuff to the + // new mapping properly uint64_t *memory = (char *)ptr - 16; uint64_t old_size = *memory; uint64_t *new_memory = _mremap(memory, old_size, size, MREMAP_MAYMOVE); if ((uint64_t)new_memory > 0xffffffffffff0000) return NULL; *new_memory = size; return (char *)new_memory + 16; +#endif + + uint64_t *memory = (char *)ptr - 16; + uint64_t old_size = *memory; + void *new = malloc(size); + char *new_dat = (char *)new + 16; + *(uint64_t *)new = size; + memcpy(new_dat, ptr, old_size); + free(ptr); + return new_dat; } -- cgit v1.2.3