diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2020-09-28 01:58:55 +0200 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2020-09-28 02:00:29 +0200 |
commit | 98c8dc5b7d43892cfb0d5d4c1ec5eca0ed7ffd49 (patch) | |
tree | 082b86045fa32e7c866183fe6e29c24138c3842c /sdn.cpp | |
parent | b99f96cf6af73eef6bb887cd28bdb6508f2dd702 (diff) | |
download | sdn-98c8dc5b7d43892cfb0d5d4c1ec5eca0ed7ffd49.tar.gz sdn-98c8dc5b7d43892cfb0d5d4c1ec5eca0ed7ffd49.tar.xz sdn-98c8dc5b7d43892cfb0d5d4c1ec5eca0ed7ffd49.zip |
Fix tilde expansion algorithm
In principle correct, in practice completely broken.
I wrongly assumed basic_string::find() would behave like strcspn(),
and also used a nonsensical string index to check for the tilde.
Diffstat (limited to 'sdn.cpp')
-rw-r--r-- | sdn.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -120,11 +120,11 @@ fun untilde (const string &path) -> string { string tail = path.substr (1); if (path[0] == '\\') return tail; - if (path[1] != '~') + if (path[0] != '~') return path; // If there is something between the ~ and the first / (or the EOS) - if (size_t until_slash = tail.find ('/')) { + if (size_t until_slash = strcspn (tail.c_str (), "/")) { if (const auto *pw = getpwnam (tail.substr (0, until_slash).c_str ())) return pw->pw_dir + tail.substr (until_slash); } else if (const auto *home = getenv ("HOME")) { |