From 31a0d99de63c3290ca05c94e20b5870f81db11f2 Mon Sep 17 00:00:00 2001 From: maxpat78 Date: Mon, 5 Aug 2024 11:10:09 +0200 Subject: [PATCH] Update bios_vhd.cpp fixes a couple corner cases, where files are in different disks or in the same directory --- src/ints/bios_vhd.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/ints/bios_vhd.cpp b/src/ints/bios_vhd.cpp index 0a29792ec9..6eeca0b318 100644 --- a/src/ints/bios_vhd.cpp +++ b/src/ints/bios_vhd.cpp @@ -49,7 +49,7 @@ * */ -// returns the path of "base" in a form relative to "child", where both exist +// returns the path of "base" in a form relative to "child" char* calc_relative_path(const char* base, const char* child) { #ifndef WIN32 char abs_base[PATH_MAX]; @@ -76,6 +76,8 @@ char* calc_relative_path(const char* base, const char* child) { // strips common subpath, if any while(*p++ == *q++); p--, q--; + // returns base if they don't share anything + if(!strcmp(p, abs_base)) return strdup(base); x = q; // count slashes while(*x) { @@ -83,8 +85,12 @@ char* calc_relative_path(const char* base, const char* child) { x++; } // allocates space for the resulting string - y = (char*)malloc(strlen(q) + n * 3); // n * strlen("..\\") + y = (char*)malloc(strlen(q) + n * 3 + 2); // n * strlen("..\\") z = y; + if(!n) { + strcpy(z, ".\\"); + z += 2; + } while(n--) { strcpy(z, "..\\"); z += 3;