From bd57e6e8ea5a8260909c7f3d0cbabd162e9b1fe1 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Fri, 1 Feb 2019 10:20:09 +0100 Subject: [PATCH] Calculate_relative_path(): do not count trailing separator --- src/io.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/io.c b/src/io.c index 58427be4..003fcd77 100644 --- a/src/io.c +++ b/src/io.c @@ -966,13 +966,15 @@ const char * Calculate_relative_path(const char * ref_path, const char * path) return path; // no common part found return absolute path // count the number of path separators in the reference path for (i = last_separator; real_ref_path[i] != '\0'; i++) - if (real_ref_path[i] == PATH_SEPARATOR[0]) + { + if (real_ref_path[i] == PATH_SEPARATOR[0] && real_ref_path[i + 1] != '\0') // do not count the trailing separator separator_count++; + } i = 0; // construct the relative path while(separator_count-- > 0) i += snprintf(rel_path + i, MAX_PATH_CHARACTERS - i, "..%s", PATH_SEPARATOR); strncpy(rel_path + i, path + last_separator + 1, MAX_PATH_CHARACTERS - i); - rel_path[MAX_PATH_CHARACTERS -1] = '\0'; + rel_path[MAX_PATH_CHARACTERS - 1] = '\0'; return rel_path; }