Skip to content

オーバフロー修正 (GetMacroFilename)#2368

Open
gorogoro123 wants to merge 1 commit intosakura-editor:masterfrom
gorogoro123:feature/fix_overflow_GetMacroFilename
Open

オーバフロー修正 (GetMacroFilename)#2368
gorogoro123 wants to merge 1 commit intosakura-editor:masterfrom
gorogoro123:feature/fix_overflow_GetMacroFilename

Conversation

@gorogoro123
Copy link
Contributor

@gorogoro123 gorogoro123 commented Feb 8, 2026

PR対象

  • アプリ(サクラエディタ本体)

カテゴリ

  • 不具合修正

PR の背景

マクロの記録開始/終了で例外が発生する(Debug build)。

https://github.com/sakura-editor/sakura/commits/253240fab1603eb8c19e23e6f7e2f0cbcecb6ed0/

  • 例外発生前
ローカル変数 +	this	0x0186fd18 {m_pCommanderView=0x0186fb80 {m_pcEditDoc=0x0183b250 {m_cDocLineMgr={...} m_cLayoutMgr={...} ...} ...} ...}	CViewCommander *	nRet	-858993460	int	nSaveResult	-858993460	int +	szInitDir	0x0153bad4 L"...	wchar_t[260] 呼び出し履歴 >	sakura.exe!CShareData::GetMacroFilename(int idx, wchar_t * pszPath, int nBufLen) 行 1158	C++	sakura.exe!CViewCommander::Command_RECKEYMACRO() 行 46	C++	sakura.exe!CViewCommander::HandleCommand(EFunctionCode nCommand, bool bRedraw, long lparam1, long lparam2, long lparam3, long lparam4) 行 520	C++	sakura.exe!CEditDoc::HandleCommand(EFunctionCode nCommand) 行 623	C++	sakura.exe!CEditWnd::OnCommand(unsigned short wNotifyCode, unsigned short wID, HWND__ * hwndCtl) 行 2219	C++	sakura.exe!CEditWnd::DispatchEvent(HWND__ * hwnd, unsigned int uMsg, unsigned int wParam, long lParam) 行 1503	C++	sakura.exe!CEditWndProc(HWND__ * hwnd, unsigned int uMsg, unsigned int wParam, long lParam) 行 224	C++ 
  • 例外発生時
ローカル変数 +	this	0xfefefefe {m_pCommanderView=??? m_pcSMacroMgr=??? m_bPrevCommand=??? }	CViewCommander *	nRet	37	int	nSaveResult	-858993460	int +	szInitDir	0x0113b684 L"C:\\work\\sakura\\Win32\\Debug\\RecKey.mac"	wchar_t[260] 呼び出し履歴 >	sakura.exe!CViewCommander::Command_RECKEYMACRO() 行 54	C++ 

仕様・動作説明

オーバフロー (GetMacroFilename) を修正します。

PR の影響範囲

影響なし。

テスト内容

ツール - マクロの記録開始 - マクロの記録終了 を実行し、例外が発生しないことを確認する。
nFolderSep = -1 になる条件の確認は、一部コードを変更して確認する。

関連 issue, PR

#2318

参考資料

https://learn.microsoft.com/en-us/cpp/c-runtime-library/crt-debug-heap-details

@github-actions
Copy link

github-actions bot commented Feb 8, 2026

Test Results

681 tests  ±0   681 ✅ ±0   2m 20s ⏱️ -1s
 82 suites ±0     0 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit ffd44ef. ± Comparison against base commit 6545412.

♻️ This comment has been updated with latest results.

@gorogoro123 gorogoro123 force-pushed the feature/fix_overflow_GetMacroFilename branch from 0f18b8d to ffd44ef Compare February 13, 2026 23:31
@beru beru added the 🐛bug🦋 ■バグ修正(Something isn't working) label Feb 17, 2026
@@ -1149,12 +1149,11 @@ int CShareData::GetMacroFilename( int idx, WCHAR *pszPath, int nBufLen )
return -nAllLen;
Copy link
Contributor

Choose a reason for hiding this comment

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

ここにチェックあるのでオーバーフローしません。

::wcsncpy_s(pszPath, nBufLen, pszDir, _TRUNCATE);
if( -1 == nFolderSep ){
*ptr2++ = L'\\';
::wcsncat_s(pszPath, nBufLen, L"\\", _TRUNCATE);
Copy link
Contributor

Choose a reason for hiding this comment

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

参考です。ここは普通にデッドコードっぽいので削除が妥当と思います。

Copy link
Contributor

Choose a reason for hiding this comment

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

いや、違いますね。

ここを通るようにグローバルな共有メモリを設定できるし、通ったとして問題ありませんでした。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐛bug🦋 ■バグ修正(Something isn't working)

3 participants