外部コマンド実行ダイアログのコマンド文字列バッファ長が1文字大きい不具合の対応 #1584
Merged
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 の目的
外部コマンド実行ダイアログのコマンドに最大の1024文字ちょうどを入力(NULL含まない)すると、コマンドは実行されますが、履歴に登録されません。
このPRではダイアログの配列サイズを1024+1から1024に修正することにより、必ず履歴に登録されるように制限します。
カテゴリ
PR の背景
動作が一貫していなくて、変な感じがすると思います。
PR のメリット
エッジケースの微妙な動作を修正できます。
PR のデメリット (トレードオフとかあれば)
1文字コマンド入力できる文字数が以前より減ります。
仕様・動作説明
履歴側の配列サイズは
typedef StaticString<WCHAR, MAX_CMDLEN> CCmdString;
と定義されていて、MAX_CMDLENがそのまま配列サイズになります。
履歴登録処理では入力チェック機構があり、そこで文字列長の確認があり、1文字長いためにはじかれて履歴に登録されないようです。
(ここはバッファを突き抜けたりはしていません)
CEditView::ExecCmd側にはさらにバッファオーバーランの問題がありますが、それは別で対処したいと思います。
PR の影響範囲
1文字コマンド入力できる文字数が以前より減ります。
CDlgExecの実装コード側は_countofなどが使われているため、特に修正は問題ないようです。
テスト内容
テスト1
手順
外部コマンド実行ダイアログで「名前」に1024文字(NULL含まない)を入力します。実行します。
再度ダイアログか履歴画面で見ても履歴に登録されていません。
コード修正後は最大文字数が1023文字になります。実行後にダイアログを再表示すると履歴に登録されています。
関連 issue, PR
参考資料