Skip to content

Commit 1444892

Browse files
authored
Fix off-by-one error in GetText() (#70)
The null terminator is not being accounted for properly in ControlWithText::GetText(). This commit fixes that.
1 parent 63610b9 commit 1444892

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Code/maxGUI/ControlWithText.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ namespace maxGUI
2121

2222
std::string ControlWithText::GetText() const noexcept {
2323
#if defined(MAX_PLATFORM_WINDOWS)
24-
size_t length_in_chars = static_cast<size_t>(SendMessage(window_handle_, WM_GETTEXTLENGTH, 0, 0));
24+
size_t length_in_chars = static_cast<size_t>(SendMessage(window_handle_, WM_GETTEXTLENGTH, 0, 0)) + 1; // +1 for the null
2525
TCHAR* buffer = new wchar_t[length_in_chars];
2626
SendMessage(window_handle_, WM_GETTEXT, length_in_chars, reinterpret_cast<LPARAM>(buffer));
27-
Win32String win32_string(std::move(buffer), std::move(length_in_chars));
27+
Win32String win32_string(std::move(buffer), length_in_chars - 1);
2828
return Win32StringToUtf8(std::move(win32_string));
2929
#endif
3030
#if defined(MAX_PLATFORM_LINUX)

0 commit comments

Comments
 (0)