Skip to content

Commit 08ef6e0

Browse files
Copilotkatahiromz
andcommitted
Address code review: simplify buffer check and add MoveFile error handling
Co-authored-by: katahiromz <2107452+katahiromz@users.noreply.github.com>
1 parent 9492a8a commit 08ef6e0

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/MBmpView.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,16 +202,16 @@ class MBmpView : public MWindowBase
202202
// MCI relies on file extension to determine media type; rename .tmp to .avi
203203
// so that compressed AVI files are properly recognized on some systems.
204204
LPTSTR pszDot = _tcsrchr(m_szTempFile, TEXT('.'));
205-
if (pszDot != NULL)
205+
if (pszDot != NULL && pszDot + 5 <= m_szTempFile + _countof(m_szTempFile))
206206
{
207-
// Ensure buffer has room for ".avi" (4 chars + null terminator)
208-
if (pszDot + 5 <= m_szTempFile + _countof(m_szTempFile))
207+
TCHAR szOldPath[MAX_PATH];
208+
_tcscpy_s(szOldPath, m_szTempFile);
209+
_tcscpy_s(pszDot, 5, TEXT(".avi")); // ".avi" + null = 5 chars
210+
// Rename the temp file created by GetTempFileName
211+
if (!MoveFile(szOldPath, m_szTempFile))
209212
{
210-
TCHAR szOldPath[MAX_PATH];
211-
_tcscpy_s(szOldPath, m_szTempFile);
212-
_tcscpy_s(pszDot, _countof(m_szTempFile) - (pszDot - m_szTempFile), TEXT(".avi"));
213-
// Rename the temp file created by GetTempFileName
214-
MoveFile(szOldPath, m_szTempFile);
213+
// Rename failed; revert to original path
214+
_tcscpy_s(m_szTempFile, szOldPath);
215215
}
216216
}
217217

0 commit comments

Comments
 (0)