Skip to content

Conversation

@gorogoro123
Copy link
Contributor

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

Copy link
Contributor

@berryzplus berryzplus left a 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() );
Copy link
Contributor

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 );
Copy link
Contributor

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 );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

指摘じゃないです。m_szFilePathはCFilePathなので、以下のように書けます。

Suggested change
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

指摘じゃないです。編集ノードの操作に責任を持つクラスがたくさんあるので、将来的にCRecentEditNodeクラスを削除すべきと思っています。

Copy link
Contributor

@beru beru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

問題無いと思います。

@beru
Copy link
Contributor

beru commented Nov 9, 2025

変更内容には関係しない事ですが、タイトルが更新されない場合にも CEditWnd::ChangeFileNameNotify の最後でファイル名変更通知をブロードキャストして CEditWnd::DispatchEventcase MYWM_TAB_WINDOW_NOTIFY で処理するのが定期的に実行されているのでもったいないなと思いました。

@beru beru merged commit a640e25 into sakura-editor:master Nov 9, 2025
11 of 12 checks passed
@gorogoro123 gorogoro123 deleted the feature/replace_wcsncpy_ChangeFileNameNotify branch November 9, 2025 03:28
@beru beru added the refactoring リファクタリング 【ChangeLog除外】 label Nov 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactoring リファクタリング 【ChangeLog除外】

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants