From a229db96a646fdb688d105988c22cb7a82169c12 Mon Sep 17 00:00:00 2001 From: Dean Jenkins Date: Sun, 24 Sep 2023 15:46:16 +0100 Subject: [PATCH] zxcc: Fix for load bios.bin failure on a RPi4 Fix load_bios() when used on a Raspberry Pi4. The defect was corrupting the path of the zxcc executable. The fix is to NUL terminate the path string from the readlink() call. --- Tools/unix/zxcc/zxcc.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Tools/unix/zxcc/zxcc.c b/Tools/unix/zxcc/zxcc.c index 21929704..0c008b55 100644 --- a/Tools/unix/zxcc/zxcc.c +++ b/Tools/unix/zxcc/zxcc.c @@ -127,7 +127,15 @@ void load_bios(void) uint32_t size = CPM_MAXPATH - 8; _NSGetExecutablePath(dir, &size); #else - readlink("/proc/self/exe", dir, CPM_MAXPATH - 8); /* allow room for bios.bin */ + ssize_t len; + len = readlink("/proc/self/exe", dir, CPM_MAXPATH - 8); /* allow room for bios.bin */ + if (len < 0) + { + /* len of -1 indicates an error occurred */ + len = 0; + } + /* Terminate the dir string with a NUL character */ + dir[len] = 0; #endif q = strrchr(dir, DIRSEPCH); *++q = 0;