-
Notifications
You must be signed in to change notification settings - Fork 176
wcsncpy 置換 (CEditWnd::ChangeFileNameNotify) #2153
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
wcsncpy 置換 (CEditWnd::ChangeFileNameNotify) #2153
Conversation
berryzplus
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
対応ありがとうございます。
|
|
||
| CRecentEditNode cRecentEditNode; | ||
| nIndex = cRecentEditNode.FindItemByHwnd( GetHwnd() ); | ||
| int nIndex = cRecentEditNode.FindItemByHwnd( GetHwnd() ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
指摘じゃないですが、 const auto で宣言すべきと思います。
int でも構わないけど const は付けるべき。
| int size = _countof( p->m_szTabCaption ) - 1; | ||
| wcsncpy( p->m_szTabCaption, pszTabCaption, size ); | ||
| p->m_szTabCaption[ size ] = L'\0'; | ||
| wcsncpy_s( p->m_szTabCaption, _countof(p->m_szTabCaption), pszTabCaption, _TRUNCATE ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
指摘じゃないです。 m_szTabCaptionが生配列なのを対策したいですが、StaticStringに移行しようとするとここを含めてあちこち変えないといけないので手が付けられない状態です。
| size = _countof2( p->m_szFilePath ) - 1; | ||
| wcsncpy( p->m_szFilePath, pszFilePath, size ); | ||
| p->m_szFilePath[ size ] = L'\0'; | ||
| wcsncpy_s( p->m_szFilePath, _countof2(p->m_szFilePath), pszFilePath, _TRUNCATE ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
指摘じゃないです。m_szFilePathはCFilePathなので、以下のように書けます。
| wcsncpy_s( p->m_szFilePath, _countof2(p->m_szFilePath), pszFilePath, _TRUNCATE ); | |
| p->m_szFilePath = pszFilePath; |
| if( nullptr == pszTabCaption ) pszTabCaption = L""; //ガード | ||
| if( nullptr == pszFilePath ) pszFilePath = L""; //ガード 2006.01.28 ryoji | ||
|
|
||
| CRecentEditNode cRecentEditNode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
指摘じゃないです。編集ノードの操作に責任を持つクラスがたくさんあるので、将来的にCRecentEditNodeクラスを削除すべきと思っています。
beru
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
問題無いと思います。
|
変更内容には関係しない事ですが、タイトルが更新されない場合にも |
PR対象
カテゴリ
PR の背景
CEditWnd::ChangeFileNameNotify() で wcsncpy() 呼び出し、null 文字を設定している。
仕様・動作説明
wcsncpy() を wcsncpy_s() に置換します。
PR の影響範囲
テスト内容
CEditWnd::ChangeFileNameNotify() 呼び出し時に、m_szTabCaption、m_szTabCaption より大きいサイズの文字列を設定して確認する。
関連 issue, PR
参考資料
https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/strncpy-s-strncpy-s-l-wcsncpy-s-wcsncpy-s-l-mbsncpy-s-mbsncpy-s-l