Skip to content

Commit

Permalink
[win] get_absolute_path() for empty string was returning uninitialize…
Browse files Browse the repository at this point in the history
…d buffer data
  • Loading branch information
dacap committed Jan 9, 2025
1 parent 41b11d6 commit 07f4e95
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion base/fs_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// LAF Base Library
// Copyright (c) 2024 Igara Studio S.A.
// Copyright (c) 2024-2025 Igara Studio S.A.
// Copyright (c) 2001-2018 David Capello
//
// This file is released under the terms of the MIT license.
Expand Down Expand Up @@ -236,6 +236,8 @@ TEST(FS, GetAbsolutePath)
{
const auto cp = get_current_path();

EXPECT_EQ("", get_absolute_path("")); // Check that empty full path is empty on all platforms

EXPECT_EQ(join_path(cp, "a"), get_absolute_path("a"));
EXPECT_EQ(join_path(cp, "a"), get_absolute_path("./a"));
EXPECT_EQ(cp, get_absolute_path("."));
Expand Down
4 changes: 2 additions & 2 deletions base/fs_win32.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// LAF Base Library
// Copyright (c) 2020-2024 Igara Studio S.A.
// Copyright (c) 2020-2025 Igara Studio S.A.
// Copyright (c) 2001-2018 David Capello
//
// This file is released under the terms of the MIT license.
Expand Down Expand Up @@ -166,7 +166,7 @@ std::string get_absolute_path(const std::string& path)
else
full = path;

TCHAR buffer[MAX_PATH + 1];
TCHAR buffer[MAX_PATH + 1] = {};
GetFullPathName(from_utf8(full).c_str(), sizeof(buffer) / sizeof(TCHAR), buffer, nullptr);
return to_utf8(buffer);
}
Expand Down

0 comments on commit 07f4e95

Please sign in to comment.