X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=vrfileman;a=blobdiff_plain;f=src%2Ffspath.cc;h=eb923d64422b378eb4761476c8c3b06a891d2aad;hp=e6677bd24181099e56db8bc778152735f2186f57;hb=33c6d11947cc6299d7b6164b2e65563e38435c74;hpb=f737a4688a44fa05c9a5ea7919819437fae85ae1 diff --git a/src/fspath.cc b/src/fspath.cc index e6677bd..eb923d6 100644 --- a/src/fspath.cc +++ b/src/fspath.cc @@ -128,6 +128,8 @@ FSPath &FSPath::operator =(FSPath &&p) void FSPath::sanitize() { + printf("sanitize: \"%s\"\n", abs_path); + // first pass, convert and backslashes to slashes char *s = abs_path; while(*s) { @@ -163,8 +165,8 @@ void FSPath::sanitize() } assert(len == (int)strlen(abs_path)); - // remove trailing slash - if(abs_path[len - 1] == '/') { + // remove trailing slash if abs_path is not just a slash (root) + if(len > 1 && abs_path[len - 1] == '/') { abs_path[--len] = 0; } assert(len == (int)strlen(abs_path)); @@ -192,7 +194,11 @@ void FSPath::sanitize() parent = 0; // root dir has no parent } else { int plen = name - 1 - abs_path; - assert(plen > 0); + assert(plen >= 0); + + if(plen == 0) { + plen = 1; // our parent is root, so we need the slash + } parent = new char[plen + 1]; memcpy(parent, abs_path, plen);