Skip to content

Commit 59381db

Browse files
committed
Merge branch 'nullpath' into 'master'
Don't build paths containing \0 See merge request OpenMW/openmw!5206
2 parents d52db6b + 5cc607c commit 59381db

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

components/files/windowspath.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,14 @@ namespace Files
6161
{
6262
// This should always be true. Note that we don't need to care above because of the trailing \0
6363
if (len % sizeof(wchar_t) == 0)
64-
return std::filesystem::path(buffer.data(), buffer.data() + len / sizeof(wchar_t));
64+
{
65+
std::wstring_view view(buffer.data(), len / sizeof(wchar_t));
66+
// Strip trailing \0 because the path constructor won't do it for us
67+
const auto pos = view.find(L'\0');
68+
if (pos != std::wstring_view::npos)
69+
view = view.substr(0, pos);
70+
return std::filesystem::path(view);
71+
}
6572
}
6673
}
6774
return {};

0 commit comments

Comments
 (0)