From 4b0f3b8fb732f82f9413588b3f142c65285ae8b9 Mon Sep 17 00:00:00 2001 From: Syed Daanish Date: Mon, 31 Aug 2026 10:15:07 +0100 Subject: [PATCH] Fix first == npos bug. --- src/internal/functions/extended.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/internal/functions/extended.cc b/src/internal/functions/extended.cc index cfd57ff..4ccdc65 100644 --- a/src/internal/functions/extended.cc +++ b/src/internal/functions/extended.cc @@ -18,7 +18,10 @@ void Function::register_extented(BEd &ctx) { auto path = std::get(arg_); const auto first = path.find_first_not_of(" \t"); const auto last = path.find_last_not_of(" \t"); - path = path.substr(first, last - first + 1); + if (first == std::string::npos) + path.clear(); + else + path = path.substr(first, last - first + 1); if (path.empty()) path = getenv("HOME"); if (path == "~") @@ -28,9 +31,8 @@ void Function::register_extented(BEd &ctx) { if (home) path = std::string(home) + path.substr(1); } - if (first != std::string::npos) - if (chdir(path.c_str()) == -1) - throw ed_error("Can't change directory."); + if (chdir(path.c_str()) == -1) + throw ed_error("Can't change directory."); }, } );