From 773e7c67cf357a152770b12a294d93fefcd83f0c Mon Sep 17 00:00:00 2001 From: Cheng Date: Wed, 25 Sep 2024 10:36:10 +0900 Subject: [PATCH] src: do not call path.back() when it is empty PR-URL: https://github.com/nodejs/node/pull/55072 Reviewed-By: Luigi Pinca Reviewed-By: Yagiz Nizipli --- src/path.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/path.cc b/src/path.cc index f1813596ff78ff..df6a11644b4c1a 100644 --- a/src/path.cc +++ b/src/path.cc @@ -266,11 +266,11 @@ std::string PathResolve(Environment* env, for (int i = numArgs - 1; i >= -1 && !resolvedAbsolute; i--) { const std::string& path = (i >= 0) ? std::string(paths[i]) : cwd; - if (static_cast(i) == numArgs - 1 && path.back() == '/') { - slashCheck = true; - } - if (!path.empty()) { + if (static_cast(i) == numArgs - 1 && path.back() == '/') { + slashCheck = true; + } + resolvedPath = std::string(path) + "/" + resolvedPath; if (path.front() == '/') {