Skip to content

Commit 066e9d1

Browse files
committed
fix
1 parent 8c00475 commit 066e9d1

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

include/fast_io_hosted/platforms/nt/nt_path.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,20 +105,25 @@ inline auto nt_call_invoke_with_directory_handle_impl(void *directory, char_type
105105

106106
auto const char16_t_size{bytes / sizeof(char16_t)};
107107

108-
rtl_alloc_guard rtl_guard{rtl_alloc_guard::allocator::allocate(char16_t_size)};
108+
rtl_alloc_guard rtl_guard{rtl_alloc_guard::allocator::allocate(char16_t_size + 1u)};
109109

110110
::fast_io::freestanding::nonoverlapped_bytes_copy_n(reinterpret_cast<::std::byte const *>(filename), bytes, reinterpret_cast<::std::byte *>(rtl_guard.ptr));
111111

112-
for (auto curr{rtl_guard.ptr}; curr != rtl_guard.ptr + char16_t_size; ++curr)
112+
auto curr{rtl_guard.ptr};
113+
for (; curr != rtl_guard.ptr + char16_t_size; ++curr)
113114
{
114115
if (*curr == u'/')
115116
{
116117
*curr = u'\\';
117118
}
118119
}
119120

121+
*curr = u'\0';
122+
120123
win32::nt::unicode_string relative_path{
121-
.Length = bytes, .MaximumLength = bytes, .Buffer = rtl_guard.ptr};
124+
.Length = bytes,
125+
.MaximumLength = static_cast<::std::uint_least16_t>(bytes + sizeof(char16_t)),
126+
.Buffer = rtl_guard.ptr};
122127
return callback(directory, __builtin_addressof(relative_path));
123128
}
124129
else if constexpr (sizeof(char_type) == sizeof(char16_t))

0 commit comments

Comments
 (0)