completion: simplify tests using test_completion_long()
[gitweb.git] / abspath.c
index 5d624307d5a68ced9ff07c7c19e2ac603c67def6..05f2d7934878a832f5a2efdf4222c16223050853 100644 (file)
--- a/abspath.c
+++ b/abspath.c
@@ -35,6 +35,9 @@ const char *real_path(const char *path)
        if (path == buf || path == next_buf)
                return path;
 
+       if (!*path)
+               die("The empty string is not a valid path");
+
        if (strlcpy(buf, path, PATH_MAX) >= PATH_MAX)
                die ("Too long path: %.*s", 60, path);
 
@@ -42,8 +45,8 @@ const char *real_path(const char *path)
                if (!is_directory(buf)) {
                        char *last_slash = find_last_dir_sep(buf);
                        if (last_slash) {
-                               *last_slash = '\0';
                                last_elem = xstrdup(last_slash + 1);
+                               last_slash[1] = '\0';
                        } else {
                                last_elem = xstrdup(buf);
                                *buf = '\0';