summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2020-09-28 01:58:55 +0200
committerPřemysl Eric Janouch <p@janouch.name>2020-09-28 02:00:29 +0200
commit98c8dc5b7d43892cfb0d5d4c1ec5eca0ed7ffd49 (patch)
tree082b86045fa32e7c866183fe6e29c24138c3842c
parentb99f96cf6af73eef6bb887cd28bdb6508f2dd702 (diff)
downloadsdn-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.
-rw-r--r--sdn.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/sdn.cpp b/sdn.cpp
index c2247b8..b9d18c4 100644
--- a/sdn.cpp
+++ b/sdn.cpp
@@ -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")) {