Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR の目的
#1525 で報告された問題に対処します。
カテゴリ
仕様・動作説明
問題の箇所は GetWindowTextLengthW で必要文字長を取得し、必要分のバッファを確保して、 GetWindowTextW にバッファ長を渡しているところです。
ここで問題になるのが API が扱う文字列長にnull文字を含むものと含まないものが混在していることで、GetWindowTextLengthW が返すのはnull文字を含まない長さですが、GetWindowTextW はnull文字を含めた長さを要求するので、どこかで1を足さなければ結果の文字列が1文字不足します。
提案する修正では basic_string::capacity() に1を足して GetWindowTextW に渡します。data() + size() にnullを書き込む操作を行いますが、C++17 では安全です。
PR の影響範囲
ApiWrap::Wnd_GetText を利用しているすべての箇所で挙動が変わります。
テスト内容
#1525 を参照してください。
関連 issue, PR
#1439