From 98c8dc5b7d43892cfb0d5d4c1ec5eca0ed7ffd49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?= Date: Mon, 28 Sep 2020 01:58:55 +0200 Subject: 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. --- sdn.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sdn.cpp') 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")) { -- cgit v1.2.3