Commit: f10b4310f76c8483ab4e40d9e71c5c3f9988fac6
Parent: b11fa4ccda5617c615edf6bf9a994f1bb96869a4
Author: Randy Palamar
Date: Thu, 17 Oct 2024 09:41:32 -0600
fix alloc alignment when using the end of the arena
Here we want to move the pointer back so we just need the masked
bits directly.
GCC still miscompiles us when any level of optimization is enabled
so there is still something to fix.
Diffstat:
3 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/build.sh b/build.sh
@@ -2,6 +2,7 @@
cflags="-march=native -O3 -std=c99 -Wall -Wextra -fno-builtin"
#cflags="${cflags} -fproc-stat-report"
#cflags="${cflags} -Rpass-missed=.*"
+#cflags="${cflags} -fsanitize=address,undefined"
ldflags="-static"
cc=${CC:-cc}
diff --git a/jdict.c b/jdict.c
@@ -181,7 +181,7 @@ static void *
alloc_(Arena *a, size len, size align, size count, u32 flags)
{
size padding;
- if (flags & ARENA_ALLOC_END) padding = -(uintptr_t)a->end & (align - 1);
+ if (flags & ARENA_ALLOC_END) padding = (uintptr_t)a->end & (align - 1);
else padding = -(uintptr_t)a->beg & (align - 1);
size available = a->end - a->beg - padding;
diff --git a/platform_linux.c b/platform_linux.c
@@ -200,7 +200,7 @@ linux_main(i32 argc, char *argv[], char *envp[])
stdout_stream.cap = 8 * MEGABYTE;
stdout_stream.data = alloc(&memory, u8, error_stream.cap, ARENA_NO_CLEAR);
- jdict(&memory, argc, argv);
+ i32 result = jdict(&memory, argc, argv);
- os_exit(0);
+ os_exit(result);
}