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

Wnd_GetText が一文字取りこぼす問題に対処 #1528

Merged
merged 1 commit into from
Feb 4, 2021
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
2 changes: 1 addition & 1 deletion sakura_core/apiwrap/StdControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace ApiWrap{
}

// ウィンドウテキストを取得するのに必要なバッファを確保する
strText.resize( cchRequired );
strText.resize( cchRequired + 1 );

// GetWindowText() はコピーした文字数を返す。
// https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowtextw
Expand Down
16 changes: 16 additions & 0 deletions tests/unittests/test-StdControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,19 @@ TEST(StdControl, Wnd_GetText)
CNativeW tempText;
ASSERT_FALSE(Wnd_GetText(NULL, tempText));
}

// GitHub #1528 の退行防止テストケース。
// 取得する文字列の長さが basic_string::capacity と同じだった場合に一文字取りこぼしていた。
TEST(StdControl, Wnd_GetText2)
{
wchar_t text[] = L"0123456789012345678901234567890123456789";

std::wstring s;
text[s.capacity()] = L'\0';

HINSTANCE hinstance = GetModuleHandleW(nullptr);
HWND hwnd = CreateWindowExW(0, L"STATIC", text, 0, 1, 1, 1, 1, nullptr, nullptr, hinstance, nullptr);
Wnd_GetText(hwnd, s);
DestroyWindow(hwnd);
berryzplus marked this conversation as resolved.
Show resolved Hide resolved
ASSERT_STREQ(s.c_str(), text);
}