From 51b4a3fc75351d6ecd2142c228d31a1f7ed52152 Mon Sep 17 00:00:00 2001 From: Omniscient <17525998+omnisci3nce@users.noreply.github.com> Date: Sun, 17 Mar 2024 15:00:53 +1100 Subject: fix a bug with dirname seg faulting when passed a string literal it doesnt like things in readonly memory i guess. now we create an arena for the obj load and create a dynamically allocated copy of the string --- src/platform/path.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/platform/path.c') diff --git a/src/platform/path.c b/src/platform/path.c index e67102b..9572941 100644 --- a/src/platform/path.c +++ b/src/platform/path.c @@ -1,12 +1,17 @@ #include "path.h" #include +#include #include +#include "mem.h" #include "str.h" #if defined(CEL_PLATFORM_LINUX) || defined(CEL_PLATFORM_MAC) -path_opt path_parent(const char* path) { - char* path_dirname = dirname(path); +path_opt path_parent(arena* a, const char* path) { + // Duplicate the string because dirname doesnt like const literals + char* path_copy = arena_alloc(a, strlen(path) + 1); + strcpy(path_copy, path); + char* path_dirname = dirname(path_copy); return (path_opt){ .path = str8_cstr_view(path_dirname), .has_value = true }; } #endif -- cgit v1.2.3-70-g09d2