Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when calling absPath with empty input #620

Merged
merged 4 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/Filesystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,14 @@ std::string common::copyToUnixPath(const std::string &_path)
/////////////////////////////////////////////////
std::string common::absPath(const std::string &_path)
{
return fs::absolute(_path).string();
std::error_code ec;
auto path = fs::absolute(_path, ec);
if (!fsWarn("absPath", ec))
{
path = "";
}

return path.string();
}

/////////////////////////////////////////////////
Expand Down
10 changes: 10 additions & 0 deletions src/Filesystem_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -636,3 +636,13 @@ TEST_F(FilesystemTest, separator)
EXPECT_EQ("\\", gz::common::separator(""));
#endif
}

/////////////////////////////////////////////////
TEST_F(FilesystemTest, empty)
{
#ifdef __APPLE__
EXPECT_EQ(common::absPath(""), gz::common::cwd() + "/");
#else
EXPECT_EQ(common::absPath(""), "");
#endif
}
Loading