From fcce662d97d6f4a5e52a0a3105462b6e933f5410 Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Sun, 2 Jul 2017 18:45:00 +0200 Subject: [PATCH] Don't use magic numbers Signed-off-by: Sven Strickroth --- src/TortoiseProc/ImportPatchDlg.cpp | 12 ++++++------ src/TortoiseProc/SyncDlg.cpp | 10 +++++----- src/Utils/MiscUI/StandAloneDlg.h | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/TortoiseProc/ImportPatchDlg.cpp b/src/TortoiseProc/ImportPatchDlg.cpp index 06c17fdd9..f29f1e6ac 100644 --- a/src/TortoiseProc/ImportPatchDlg.cpp +++ b/src/TortoiseProc/ImportPatchDlg.cpp @@ -655,14 +655,14 @@ BOOL CImportPatchDlg::PreTranslateMessage(MSG* pMsg) case VK_ESCAPE: case VK_CANCEL: { - TCHAR buff[128] = { 0 }; - ::GetClassName(pMsg->hwnd,buff,128); + TCHAR buff[129]; + ::GetClassName(pMsg->hwnd, buff, _countof(buff) - 1); /* Use MSFTEDIT_CLASS http://msdn.microsoft.com/en-us/library/bb531344.aspx */ - if (_wcsnicmp(buff, MSFTEDIT_CLASS, 128) == 0 || //Unicode and MFC 2012 and later - _wcsnicmp(buff, RICHEDIT_CLASS, 128) == 0 || //ANSI or MFC 2010 - _wcsnicmp(buff, L"Scintilla", 128) == 0 || - _wcsnicmp(buff, L"SysListView32", 128) == 0 || + if (_wcsnicmp(buff, MSFTEDIT_CLASS, _countof(buff) - 1) == 0 || //Unicode and MFC 2012 and later + _wcsnicmp(buff, RICHEDIT_CLASS, _countof(buff) - 1) == 0 || //ANSI or MFC 2010 + _wcsnicmp(buff, L"Scintilla", _countof(buff) - 1) == 0 || + _wcsnicmp(buff, L"SysListView32", _countof(buff) - 1) == 0 || ::GetParent(pMsg->hwnd) == this->m_ctrlTabCtrl.m_hWnd) { this->PostMessage(WM_KEYDOWN,VK_ESCAPE,0); diff --git a/src/TortoiseProc/SyncDlg.cpp b/src/TortoiseProc/SyncDlg.cpp index 240b254f2..e4dae6ac9 100644 --- a/src/TortoiseProc/SyncDlg.cpp +++ b/src/TortoiseProc/SyncDlg.cpp @@ -1206,13 +1206,13 @@ BOOL CSyncDlg::PreTranslateMessage(MSG* pMsg) case VK_ESCAPE: case VK_CANCEL: { - TCHAR buff[128] = { 0 }; - ::GetClassName(pMsg->hwnd,buff,128); + TCHAR buff[129]; + ::GetClassName(pMsg->hwnd, buff, _countof(buff) - 1); /* Use MSFTEDIT_CLASS http://msdn.microsoft.com/en-us/library/bb531344.aspx */ - if (_wcsnicmp(buff, MSFTEDIT_CLASS, 128) == 0 || //Unicode and MFC 2012 and later - _wcsnicmp(buff, RICHEDIT_CLASS, 128) == 0 || //ANSI or MFC 2010 - _wcsnicmp(buff, L"SysListView32", 128) == 0) + if (_wcsnicmp(buff, MSFTEDIT_CLASS, _countof(buff) - 1) == 0 || //Unicode and MFC 2012 and later + _wcsnicmp(buff, RICHEDIT_CLASS, _countof(buff) - 1) == 0 || //ANSI or MFC 2010 + _wcsnicmp(buff, L"SysListView32", _countof(buff) - 1) == 0) { this->PostMessage(WM_KEYDOWN,VK_ESCAPE,0); return TRUE; diff --git a/src/Utils/MiscUI/StandAloneDlg.h b/src/Utils/MiscUI/StandAloneDlg.h index 238bd99ba..7a843f6c0 100644 --- a/src/Utils/MiscUI/StandAloneDlg.h +++ b/src/Utils/MiscUI/StandAloneDlg.h @@ -71,9 +71,9 @@ protected: if (nVirtKey == 'A' && (GetKeyState(VK_CONTROL) & 0x8000 ) ) { TCHAR buffer[129]; - ::GetClassName(pMsg->hwnd, buffer,128); + ::GetClassName(pMsg->hwnd, buffer, _countof(buffer) - 1); - if (_wcsnicmp(buffer, L"EDIT", 128) == 0) + if (_wcsnicmp(buffer, L"EDIT", _countof(buffer) - 1) == 0) { ::PostMessage(pMsg->hwnd,EM_SETSEL,0,-1); return TRUE; -- 2.11.4.GIT