]> Sergey Matveev's repositories - nnn.git/commitdiff
Fix prefix calcualtion
authorArun Prakash Jana <engineerarun@gmail.com>
Sun, 9 Feb 2020 02:51:12 +0000 (08:21 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Sun, 9 Feb 2020 02:51:12 +0000 (08:21 +0530)
src/nnn.c

index 3af9347f556172d8903c0a30a00154fbce5df64c..913e4e79f3abb2a852724fce05aab1b04e344091 100644 (file)
--- 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';