From e31867290451d0cd5ee2f34837911cd7d6d9795e Mon Sep 17 00:00:00 2001 From: Arun Prakash Jana Date: Sun, 9 Feb 2020 08:21:12 +0530 Subject: Fix prefix calcualtion --- src/nnn.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/nnn.c') diff --git a/src/nnn.c b/src/nnn.c index 3af9347..913e4e7 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -964,21 +964,19 @@ static char *common_prefix(const char *path, char *prefix) while (*x && *y && (*x == *y)) ++x, ++y; - /* Strings are same OR prefix is shorter */ - if ((!*x && !*y) || !*y) + /* Strings are same */ + if (!*x && !*y) return prefix; /* Path is shorter */ - if (!*x) { - xstrlcpy(prefix, path, path - x + 1); + if (!*x && *y == '/') { + xstrlcpy(prefix, path, y - path); return prefix; } - /* Paths deviate and prefix ends with '/' */ - if (y != prefix && *y == '/') { - prefix[y - prefix] = '\0'; + /* Prefix is shorter */ + if (!*y && *x == '/') return prefix; - } /* Shorten prefix */ prefix[y - prefix] = '\0'; -- cgit v1.2.3-70-g09d2