From 59ead584bcde1637166b1c87be8b54ec37fb3a69 Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Tue, 23 Oct 2018 08:37:05 +0200 Subject: [PATCH] Use min and max of the C++ STL Signed-off-by: Sven Strickroth --- src/Git/GitDataObject.cpp | 4 ++-- src/Git/GitStatusListCtrl.cpp | 2 +- src/GitWCRev/stdafx.h | 8 ++++++-- src/TGitCache/stdafx.h | 8 ++++++-- src/TortoiseGitBlame/stdafx.h | 8 ++++++-- src/TortoiseIDiff/PicWindow.cpp | 10 +++++----- src/TortoiseIDiff/stdafx.h | 6 +++++- src/TortoiseMerge/BaseView.cpp | 10 +++++----- src/TortoiseMerge/LocatorBar.cpp | 8 ++++---- src/TortoiseMerge/stdafx.h | 8 ++++++-- src/TortoiseProc/FileDiffDlg.cpp | 2 +- src/TortoiseProc/GitLogListBase.cpp | 4 ++-- src/TortoiseProc/HistoryDlg.cpp | 4 ++-- .../RevisionGraph/RevisionGraphDlgDraw.cpp | 14 +++++++------- .../RevisionGraph/RevisionGraphDlgFunc.cpp | 6 +++--- .../RevisionGraph/RevisionGraphWnd.cpp | 6 ++---- src/TortoiseProc/RevisionGraph/RevisionGraphWnd.h | 2 -- src/TortoiseProc/StatGraphDlg.cpp | 2 +- src/TortoiseProc/UpdateCrypto.cpp | 22 +++++++++++----------- src/TortoiseProc/VersioncheckParser.cpp | 2 +- src/TortoiseProc/stdafx.h | 8 ++++++-- src/TortoiseShell/ContextMenu.cpp | 2 +- src/TortoiseShell/stdafx.h | 6 +++++- src/TortoiseUDiff/TortoiseUDiff.cpp | 3 +-- src/TortoiseUDiff/stdafx.h | 7 ++++++- src/Utils/MiscUI/AnimationManager.cpp | 1 - src/Utils/MiscUI/MyGraph.cpp | 4 ++-- src/Utils/PathWatcher.cpp | 6 +++--- test/Cache/CacheDlg.cpp | 6 +++--- test/Cache/stdafx.h | 6 +++++- test/UnitTests/stdafx.h | 6 +++++- 31 files changed, 113 insertions(+), 78 deletions(-) diff --git a/src/Git/GitDataObject.cpp b/src/Git/GitDataObject.cpp index d14223f62..9bedf0351 100644 --- a/src/Git/GitDataObject.cpp +++ b/src/Git/GitDataObject.cpp @@ -1,4 +1,4 @@ -// TortoiseGit - a Windows shell extension for easy version control +// TortoiseGit - a Windows shell extension for easy version control // Copyright (C) 2016-2018 - TortoiseGit // Copyright (C) 2007-2014 - TortoiseSVN @@ -167,7 +167,7 @@ STDMETHODIMP GitDataObject::GetData(FORMATETC* pformatetcIn, STGMEDIUM* pmedium) m_allPaths.push_back(m_gitPaths[i]); } - size_t dataSize = sizeof(FILEGROUPDESCRIPTOR) + ((max(1, m_allPaths.size()) - 1) * sizeof(FILEDESCRIPTOR)); + size_t dataSize = sizeof(FILEGROUPDESCRIPTOR) + ((max((size_t)1, m_allPaths.size()) - 1) * sizeof(FILEDESCRIPTOR)); HGLOBAL data = GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE | GMEM_ZEROINIT, dataSize); FILEGROUPDESCRIPTOR* files = (FILEGROUPDESCRIPTOR*)GlobalLock(data); diff --git a/src/Git/GitStatusListCtrl.cpp b/src/Git/GitStatusListCtrl.cpp index 56159b276..774f8dc84 100644 --- a/src/Git/GitStatusListCtrl.cpp +++ b/src/Git/GitStatusListCtrl.cpp @@ -3908,7 +3908,7 @@ void CGitStatusListCtrl::Clear() bool CGitStatusListCtrl::CheckMultipleDiffs() { UINT selCount = GetSelectedCount(); - if (selCount > max(3, (DWORD)CRegDWORD(L"Software\\TortoiseGit\\NumDiffWarning", 10))) + if (selCount > max((DWORD)3, (DWORD)CRegDWORD(L"Software\\TortoiseGit\\NumDiffWarning", 10))) { CString message; message.Format(IDS_STATUSLIST_WARN_MAXDIFF, selCount); diff --git a/src/GitWCRev/stdafx.h b/src/GitWCRev/stdafx.h index 05706a1bd..8bd51879f 100644 --- a/src/GitWCRev/stdafx.h +++ b/src/GitWCRev/stdafx.h @@ -1,4 +1,4 @@ -// stdafx.h : include file for standard system include files, +// stdafx.h : include file for standard system include files, // or project specific include files that are used frequently, // but are changed infrequently @@ -6,6 +6,11 @@ #define _CRT_SECURE_NO_WARNINGS +#define NOMINMAX +#include +using std::max; +using std::min; + #include "../targetver.h" #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers @@ -17,7 +22,6 @@ #include #include #include -#include #include #include diff --git a/src/TGitCache/stdafx.h b/src/TGitCache/stdafx.h index d6fdfe758..74a491880 100644 --- a/src/TGitCache/stdafx.h +++ b/src/TGitCache/stdafx.h @@ -1,4 +1,4 @@ -// stdafx.h : include file for standard system include files, +// stdafx.h : include file for standard system include files, // or project specific include files that are used frequently, but // are changed infrequently // @@ -7,6 +7,11 @@ #include "../targetver.h" +#define NOMINMAX +#include +using std::min; +using std::max; + #include #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit #define CSTRING_AVAILABLE @@ -31,7 +36,6 @@ using namespace ATL; #include #include #include -#include #include #include diff --git a/src/TortoiseGitBlame/stdafx.h b/src/TortoiseGitBlame/stdafx.h index f85f17dc0..fd63d5f11 100644 --- a/src/TortoiseGitBlame/stdafx.h +++ b/src/TortoiseGitBlame/stdafx.h @@ -1,4 +1,4 @@ - + // stdafx.h : include file for standard system include files, // or project specific include files that are used frequently, // but are changed infrequently @@ -15,6 +15,11 @@ #include "../targetver.h" +#define NOMINMAX +#include +using std::max; +using std::min; + #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit @@ -50,7 +55,6 @@ #include #include #include -#include #include #define USE_GDI_GRADIENT diff --git a/src/TortoiseIDiff/PicWindow.cpp b/src/TortoiseIDiff/PicWindow.cpp index 6546654e3..1603ef018 100644 --- a/src/TortoiseIDiff/PicWindow.cpp +++ b/src/TortoiseIDiff/PicWindow.cpp @@ -438,7 +438,7 @@ LRESULT CALLBACK CPicWindow::WinMsgHandler(HWND hwnd, UINT uMsg, WPARAM wParam, if (nCurrentFrame > picture.GetNumberOfFrames(0)) nCurrentFrame = 1; long delay = picture.SetActiveFrame(nCurrentFrame); - delay = max(100, delay); + delay = max(100l, delay); SetTimer(*this, ID_ANIMATIONTIMER, delay, nullptr); InvalidateRect(*this, nullptr, FALSE); } @@ -623,7 +623,7 @@ void CPicWindow::DrawViewTitle(HDC hDC, RECT * rect) int nStringLength = stringsize.cx; int texttop = pSecondPic ? textrect.top + (header_height /2) - stringsize.cy : textrect.top + (header_height /2) - stringsize.cy/2; ExtTextOut(hDC, - max(textrect.left + ((textrect.right-textrect.left)-nStringLength)/2, 1), + max(textrect.left + ((textrect.right - textrect.left) - nStringLength) / 2, 1l), texttop, ETO_CLIPPED, &textrect, @@ -634,7 +634,7 @@ void CPicWindow::DrawViewTitle(HDC hDC, RECT * rect) { realtitle = (pictitle2.empty() ? picpath2 : pictitle2); ExtTextOut(hDC, - max(textrect.left + ((textrect.right-textrect.left)-nStringLength)/2, 1), + max(textrect.left + ((textrect.right - textrect.left) - nStringLength) / 2, 1l), texttop + stringsize.cy, ETO_CLIPPED, &textrect, @@ -650,7 +650,7 @@ void CPicWindow::DrawViewTitle(HDC hDC, RECT * rect) int nStringLength = stringsize.cx; ExtTextOut(hDC, - max(textrect.left + ((textrect.right-textrect.left)-nStringLength)/2, 1), + max(textrect.left + ((textrect.right - textrect.left) - nStringLength) / 2, 1l), textrect.top + header_height + (header_height /2) - stringsize.cy/2, ETO_CLIPPED, &textrect, @@ -1364,7 +1364,7 @@ void CPicWindow::Paint(HWND hwnd) int nStringLength = stringsize.cx; ExtTextOut(memDC, - max(rect.left + ((rect.right-rect.left)-nStringLength)/2, 1), + max(rect.left + ((rect.right - rect.left) - nStringLength) / 2, 1l), rect.top + ((rect.bottom-rect.top) - stringsize.cy)/2, ETO_CLIPPED, &rect, diff --git a/src/TortoiseIDiff/stdafx.h b/src/TortoiseIDiff/stdafx.h index dc2ce1dee..30e106d37 100644 --- a/src/TortoiseIDiff/stdafx.h +++ b/src/TortoiseIDiff/stdafx.h @@ -1,4 +1,4 @@ -// stdafx.h : include file for standard system include files, +// stdafx.h : include file for standard system include files, // or project specific include files that are used frequently, but // are changed infrequently // @@ -11,6 +11,10 @@ #include "../targetver.h" +#define NOMINMAX +#include +using std::max; +using std::min; #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit diff --git a/src/TortoiseMerge/BaseView.cpp b/src/TortoiseMerge/BaseView.cpp index 1cff3aa21..4ff4c2ffa 100644 --- a/src/TortoiseMerge/BaseView.cpp +++ b/src/TortoiseMerge/BaseView.cpp @@ -2968,7 +2968,7 @@ BOOL CBaseView::OnToolTipNotify(UINT /*id*/, NMHDR *pNMHDR, LRESULT *pResult) else { TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR; - lstrcpyn(m_wszTip, strTipText, min(strTipText.GetLength() + 1, _countof(m_wszTip) - 1)); + lstrcpyn(m_wszTip, strTipText, min(strTipText.GetLength() + 1, (int)_countof(m_wszTip) - 1)); pTTTW->lpszText = m_wszTip; } @@ -3057,7 +3057,7 @@ void CBaseView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { POINT ptCaretPos = GetCaretPosition(); ptCaretPos.y -= GetScreenLines(); - ptCaretPos.y = max(ptCaretPos.y, 0); + ptCaretPos.y = max(ptCaretPos.y, 0l); ptCaretPos.x = CalculateCharIndex(ptCaretPos.y, m_nCaretGoalPos); SetCaretPosition(ptCaretPos); OnCaretMove(MOVELEFT, bShift); @@ -3611,7 +3611,7 @@ void CBaseView::UpdateCaret() { POINT pt = { ptCaretPos.x + 1, ptCaretPos.y }; POINT pt2 = TextToClient(pt); - int width = max(GetCharWidth(), pt2.x - pt1.x); + int width = max(GetCharWidth(), (int)(pt2.x - pt1.x)); CreateSolidCaret(width, GetLineHeight()); } SetCaretPos(pt1); @@ -3645,7 +3645,7 @@ POINT CBaseView::ConvertViewPosToScreen(const POINT& pt) { POINT ptPos; int nViewLineLenLeft = GetViewLineLength(pt.y); - ptPos.x = min(nViewLineLenLeft, pt.x); + ptPos.x = min((LONG)nViewLineLenLeft, pt.x); ptPos.y = FindScreenLineForViewLine(pt.y); if (GetViewLineForScreen(ptPos.y) != pt.y ) { @@ -3791,7 +3791,7 @@ int CBaseView::CalcColFromPoint(int xpos, int lineIndex) POINT CBaseView::TextToClient(const POINT& point) { POINT pt; - int nOffsetScreenLine = max(0, (point.y - m_nTopLine)); + int nOffsetScreenLine = max(0, (int)(point.y - m_nTopLine)); pt.y = nOffsetScreenLine * GetLineHeight(); pt.x = CalculateActualOffset(point); diff --git a/src/TortoiseMerge/LocatorBar.cpp b/src/TortoiseMerge/LocatorBar.cpp index 716e83ce8..3afe185d7 100644 --- a/src/TortoiseMerge/LocatorBar.cpp +++ b/src/TortoiseMerge/LocatorBar.cpp @@ -1,4 +1,4 @@ -// TortoiseGitMerge - a Diff/Patch program +// TortoiseGitMerge - a Diff/Patch program // Copyright (C) 2006-2012, 2015 - TortoiseSVN @@ -291,7 +291,7 @@ void CLocatorBar::PaintView(CDC& cacheDC, CBaseView* view, CDWordArray& indents, if ((DiffStates)state != DIFFSTATE_NORMAL) { cacheDC.FillSolidRect(rect.left + (width*stripeIndex/3), height*linecount/m_nLines, - barwidth, max(height*identcount/m_nLines,1), color); + barwidth, max((int)(height * identcount / m_nLines), 1), (int)color); } linecount += identcount; } @@ -305,7 +305,7 @@ void CLocatorBar::PaintView(CDC& cacheDC, CBaseView* view, CDWordArray& indents, if (view->m_arMarkedWordLines[i]) { cacheDC.FillSolidRect(rect.left + (width*stripeIndex/3), (int)(height*i/m_nLines), - barwidth, max(height/m_nLines,2), color); + barwidth, max((int)(height / m_nLines), 2), (int)color); } } } @@ -319,7 +319,7 @@ void CLocatorBar::PaintView(CDC& cacheDC, CBaseView* view, CDWordArray& indents, if (view->m_arFindStringLines[i]) { cacheDC.FillSolidRect(rect.left + (width*stripeIndex/3), (int)(height*i/m_nLines), - barwidth, max(height/m_nLines,2), color); + barwidth, max((int)(height / m_nLines), 2), (int)color); } } } diff --git a/src/TortoiseMerge/stdafx.h b/src/TortoiseMerge/stdafx.h index 83439eda7..cd85bdaaa 100644 --- a/src/TortoiseMerge/stdafx.h +++ b/src/TortoiseMerge/stdafx.h @@ -1,4 +1,4 @@ -// stdafx.h : include file for standard system include files, +// stdafx.h : include file for standard system include files, // or project specific include files that are used frequently, // but are changed infrequently @@ -12,6 +12,11 @@ #include "../targetver.h" +#define NOMINMAX +#include +using std::max; +using std::min; + #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit // turns off MFC's hiding of some common and often safely ignored warning messages @@ -47,7 +52,6 @@ #include #include #include -#include #pragma warning(push) #include "apr_general.h" diff --git a/src/TortoiseProc/FileDiffDlg.cpp b/src/TortoiseProc/FileDiffDlg.cpp index 827046176..093542eaf 100644 --- a/src/TortoiseProc/FileDiffDlg.cpp +++ b/src/TortoiseProc/FileDiffDlg.cpp @@ -1383,7 +1383,7 @@ void CFileDiffDlg::OnBnClickedLog() bool CFileDiffDlg::CheckMultipleDiffs() { UINT selCount = m_cFileList.GetSelectedCount(); - if (selCount > max(3, (DWORD)CRegDWORD(L"Software\\TortoiseGit\\NumDiffWarning", 10))) + if (selCount > max((DWORD)3, (DWORD)CRegDWORD(L"Software\\TortoiseGit\\NumDiffWarning", 10))) { CString message; message.Format(IDS_STATUSLIST_WARN_MAXDIFF, selCount); diff --git a/src/TortoiseProc/GitLogListBase.cpp b/src/TortoiseProc/GitLogListBase.cpp index 50edfd7dc..efcf286d5 100644 --- a/src/TortoiseProc/GitLogListBase.cpp +++ b/src/TortoiseProc/GitLogListBase.cpp @@ -139,8 +139,8 @@ CGitLogListBase::CGitLogListBase() : CHintCtrlGetTextExtent(sEntry); - horizExtent = max(horizExtent, itemExtent.cx+5); + horizExtent = max(horizExtent, (int)itemExtent.cx + 5); } m_List.SetHorizontalExtent(horizExtent); ReleaseDC(pDC); diff --git a/src/TortoiseProc/RevisionGraph/RevisionGraphDlgDraw.cpp b/src/TortoiseProc/RevisionGraph/RevisionGraphDlgDraw.cpp index d763cf89e..dc46ae47f 100644 --- a/src/TortoiseProc/RevisionGraph/RevisionGraphDlgDraw.cpp +++ b/src/TortoiseProc/RevisionGraph/RevisionGraphDlgDraw.cpp @@ -290,9 +290,9 @@ void CRevisionGraphWnd::DrawMarker if (num == 1) { // Roman number 1 - REAL x = max(1, 10 * this->m_fZoomFactor); - REAL y1 = max(1, 25 * this->m_fZoomFactor); - REAL y2 = max(1, 5 * this->m_fZoomFactor); + REAL x = max(1.0f, 10 * this->m_fZoomFactor); + REAL y1 = max(1.0f, 25 * this->m_fZoomFactor); + REAL y2 = max(1.0f, 5 * this->m_fZoomFactor); if(graphics.graphics) { graphics.graphics->DrawLine(&pen, noderect.X + x, noderect.Y - y1, noderect.X + x, noderect.Y - y2); @@ -310,10 +310,10 @@ void CRevisionGraphWnd::DrawMarker else if (num == 2) { // Roman number 2 - REAL x1 = max(1, 5 * this->m_fZoomFactor); - REAL x2 = max(1, 15 * this->m_fZoomFactor); - REAL y1 = max(1, 25 * this->m_fZoomFactor); - REAL y2 = max(1, 5 * this->m_fZoomFactor); + REAL x1 = max(1.0f, 5 * this->m_fZoomFactor); + REAL x2 = max(1.0f, 15 * this->m_fZoomFactor); + REAL y1 = max(1.0f, 25 * this->m_fZoomFactor); + REAL y2 = max(1.0f, 5 * this->m_fZoomFactor); if(graphics.graphics) { graphics.graphics->DrawLine(&pen, noderect.X + x1, noderect.Y - y1, noderect.X + x1, noderect.Y - y2); diff --git a/src/TortoiseProc/RevisionGraph/RevisionGraphDlgFunc.cpp b/src/TortoiseProc/RevisionGraph/RevisionGraphDlgFunc.cpp index acd503b61..0c94a15d7 100644 --- a/src/TortoiseProc/RevisionGraph/RevisionGraphDlgFunc.cpp +++ b/src/TortoiseProc/RevisionGraph/RevisionGraphDlgFunc.cpp @@ -68,8 +68,8 @@ void CRevisionGraphWnd::BuildPreview() // make sure the preview window has a minimal size - m_previewWidth = (int)min (max (graphRect.Width() * m_previewZoom, 30), preViewSize.cx); - m_previewHeight = (int)min (max (graphRect.Height() * m_previewZoom, 30), preViewSize.cy); + m_previewWidth = min((LONG)max(graphRect.Width() * m_previewZoom, 30.0f), preViewSize.cx); + m_previewHeight = min((LONG)max(graphRect.Height() * m_previewZoom, 30.0f), preViewSize.cy); CClientDC ddc(this); CDC dc; @@ -408,7 +408,7 @@ void CRevisionGraphWnd::DoZoom (float fZoomFactor, bool updateScrollbars) m_nFontSize = max(1, int(DEFAULT_ZOOM_FONT * fZoomFactor)); if (m_nFontSize < SMALL_ZOOM_FONT_THRESHOLD) - m_nFontSize = min (SMALL_ZOOM_FONT_THRESHOLD, int(SMALL_ZOOM_FONT * fZoomFactor)); + m_nFontSize = min((int)SMALL_ZOOM_FONT_THRESHOLD, int(SMALL_ZOOM_FONT * fZoomFactor)); for (int i = 0; i < MAXFONTS; ++i) { diff --git a/src/TortoiseProc/RevisionGraph/RevisionGraphWnd.cpp b/src/TortoiseProc/RevisionGraph/RevisionGraphWnd.cpp index 445bb542c..2437dc565 100644 --- a/src/TortoiseProc/RevisionGraph/RevisionGraphWnd.cpp +++ b/src/TortoiseProc/RevisionGraph/RevisionGraphWnd.cpp @@ -37,13 +37,11 @@ #pragma warning(push) #pragma warning(disable: 4100) // unreferenced formal parameter -#undef max #include #include #include #include #include -#define max(a, b) (((a) > (b)) ? (a) : (b)) #pragma warning(pop) #ifdef _DEBUG @@ -1533,12 +1531,12 @@ LRESULT CRevisionGraphWnd::OnWorkerThreadDone(WPARAM, LPARAM) sinfo.cbSize = sizeof(SCROLLINFO); if (GetScrollInfo(SB_HORZ, &sinfo)) { - sinfo.nPos = (int)min(max(sinfo.nMin, m_GraphAttr.x(m_HeadNode) - m_GraphAttr.width(m_HeadNode) / 2), sinfo.nMax); + sinfo.nPos = min(max(sinfo.nMin, (int)(m_GraphAttr.x(m_HeadNode) - m_GraphAttr.width(m_HeadNode) / 2)), sinfo.nMax); SetScrollInfo(SB_HORZ, &sinfo); } if (GetScrollInfo(SB_VERT, &sinfo)) { - sinfo.nPos = (int)min(max(sinfo.nMin, m_GraphAttr.y(m_HeadNode) - m_GraphAttr.height(m_HeadNode) / 2), sinfo.nMax); + sinfo.nPos = min(max(sinfo.nMin, (int)(m_GraphAttr.y(m_HeadNode) - m_GraphAttr.height(m_HeadNode) / 2)), sinfo.nMax); SetScrollInfo(SB_VERT, &sinfo); } } diff --git a/src/TortoiseProc/RevisionGraph/RevisionGraphWnd.h b/src/TortoiseProc/RevisionGraph/RevisionGraphWnd.h index 5472c27c8..87c15d431 100644 --- a/src/TortoiseProc/RevisionGraph/RevisionGraphWnd.h +++ b/src/TortoiseProc/RevisionGraph/RevisionGraphWnd.h @@ -28,13 +28,11 @@ #pragma warning(push) #pragma warning(disable: 4100) // unreferenced formal parameter -#undef max #include #include #include #include #include -#define max(a, b) (((a) > (b)) ? (a) : (b)) #pragma warning(pop) using namespace Gdiplus; diff --git a/src/TortoiseProc/StatGraphDlg.cpp b/src/TortoiseProc/StatGraphDlg.cpp index 5d5628583..051204aec 100644 --- a/src/TortoiseProc/StatGraphDlg.cpp +++ b/src/TortoiseProc/StatGraphDlg.cpp @@ -142,7 +142,7 @@ void CStatGraphDlg::SetSkipper (bool reloadSkiper) // the resolution limit of the screen will already not allow for displaying // it in a reasonable way - int max_authors_count = max(1, (int)min(m_authorNames.size(), 250) ); + int max_authors_count = max(1, (int)min(m_authorNames.size(), (size_t)250)); m_Skipper.SetRange (1, max_authors_count); m_Skipper.SetPageSize(5); diff --git a/src/TortoiseProc/UpdateCrypto.cpp b/src/TortoiseProc/UpdateCrypto.cpp index cbc3d1f73..9c160334b 100644 --- a/src/TortoiseProc/UpdateCrypto.cpp +++ b/src/TortoiseProc/UpdateCrypto.cpp @@ -1,7 +1,7 @@ -// TortoiseGit - a Windows shell extension for easy version control +// TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2013-2017 Sven Strickroth -// Copyright (C) 2014-2017 TortoiseGit +// Copyright (C) 2013-2018 Sven Strickroth +// Copyright (C) 2014-2018 TortoiseGit // Copyright (C) VLC project (http://videolan.org) // - pgp parsing code was copied from src/misc/update(_crypto)?.c // Copyright (C) The Internet Society (1998). All Rights Reserved. @@ -834,8 +834,8 @@ static int check_hash(HCRYPTHASH hHash, signature_packet_t *p_sig) */ static int verify_signature_rsa(HCRYPTPROV hCryptProv, HCRYPTHASH hHash, public_key_t& p_pkey, signature_packet_t& p_sig) { - int i_n_len = min(mpi_len(p_pkey.key.sig.rsa.n), sizeof(p_pkey.key.sig.rsa.n) - 2); - int i_s_len = min(mpi_len(p_sig.algo_specific.rsa.s), sizeof(p_sig.algo_specific.rsa.s) - 2); + int i_n_len = min(mpi_len(p_pkey.key.sig.rsa.n), (int)sizeof(p_pkey.key.sig.rsa.n) - 2); + int i_s_len = min(mpi_len(p_sig.algo_specific.rsa.s), (int)sizeof(p_sig.algo_specific.rsa.s) - 2); if (i_s_len > i_n_len) return -1; @@ -879,12 +879,12 @@ static int verify_signature_dsa(HCRYPTPROV hCryptProv, HCRYPTHASH hHash, public_ if (p_sig.digest_algo != DIGEST_ALGO_SHA1) // PROV_DSS only supports SHA1 signatures, see http://msdn.microsoft.com/en-us/library/windows/desktop/aa387434%28v=vs.85%29.aspx return -1; - int i_p_len = min(mpi_len(p_pkey.key.sig.dsa.p), sizeof(p_pkey.key.sig.dsa.p) - 2); - int i_q_len = min(mpi_len(p_pkey.key.sig.dsa.q), sizeof(p_pkey.key.sig.dsa.q) - 2); - int i_g_len = min(mpi_len(p_pkey.key.sig.dsa.g), sizeof(p_pkey.key.sig.dsa.g) - 2); - int i_y_len = min(mpi_len(p_pkey.key.sig.dsa.y), sizeof(p_pkey.key.sig.dsa.y) - 2); - int i_r_len = min(mpi_len(p_sig.algo_specific.dsa.r), sizeof(p_sig.algo_specific.dsa.r) - 2); - int i_s_len = min(mpi_len(p_sig.algo_specific.dsa.s), sizeof(p_sig.algo_specific.dsa.s) - 2); + int i_p_len = min(mpi_len(p_pkey.key.sig.dsa.p), (int)sizeof(p_pkey.key.sig.dsa.p) - 2); + int i_q_len = min(mpi_len(p_pkey.key.sig.dsa.q), (int)sizeof(p_pkey.key.sig.dsa.q) - 2); + int i_g_len = min(mpi_len(p_pkey.key.sig.dsa.g), (int)sizeof(p_pkey.key.sig.dsa.g) - 2); + int i_y_len = min(mpi_len(p_pkey.key.sig.dsa.y), (int)sizeof(p_pkey.key.sig.dsa.y) - 2); + int i_r_len = min(mpi_len(p_sig.algo_specific.dsa.r), (int)sizeof(p_sig.algo_specific.dsa.r) - 2); + int i_s_len = min(mpi_len(p_sig.algo_specific.dsa.s), (int)sizeof(p_sig.algo_specific.dsa.s) - 2); // CryptoAPI only supports 1024-bit DSA keys and SHA1 signatures if (i_p_len > 128 || i_q_len > 20 && i_g_len > 128 || i_y_len > 128 || i_r_len > 20 || i_s_len > 20) diff --git a/src/TortoiseProc/VersioncheckParser.cpp b/src/TortoiseProc/VersioncheckParser.cpp index 1761ac13e..e1b29e936 100644 --- a/src/TortoiseProc/VersioncheckParser.cpp +++ b/src/TortoiseProc/VersioncheckParser.cpp @@ -38,7 +38,7 @@ static CString GetConfigValue(const wchar_t* ptr) CString value; { - CStrBuf working(value, (int)min(wcslen(ptr), UINT16_MAX)); + CStrBuf working(value, (int)min(wcslen(ptr), (size_t)UINT16_MAX)); wchar_t* fixed = working; bool quoted = false; diff --git a/src/TortoiseProc/stdafx.h b/src/TortoiseProc/stdafx.h index cbb8f5c7b..3fa28cd57 100644 --- a/src/TortoiseProc/stdafx.h +++ b/src/TortoiseProc/stdafx.h @@ -1,4 +1,4 @@ -// stdafx.h : include file for standard system include files, +// stdafx.h : include file for standard system include files, // or project specific include files that are used frequently, // but are changed infrequently @@ -9,6 +9,11 @@ #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit +#define NOMINMAX +#include +using std::max; +using std::min; + // turns off MFC's hiding of some common and often safely ignored warning messages #define _AFX_ALL_WARNINGS @@ -38,7 +43,6 @@ #include #include #include -#include #include #include diff --git a/src/TortoiseShell/ContextMenu.cpp b/src/TortoiseShell/ContextMenu.cpp index 51a56d402..dcaeec656 100644 --- a/src/TortoiseShell/ContextMenu.cpp +++ b/src/TortoiseShell/ContextMenu.cpp @@ -2109,7 +2109,7 @@ bool CShellExt::InsertIgnoreSubmenus(UINT &idCmd, UINT idCmdFirst, HMENU hMenu, else GetMenuTextFromResource(ShellMenuIgnoreSub); menuiteminfo.dwTypeData = stringtablebuffer; - menuiteminfo.cch = (UINT)min(wcslen(menuiteminfo.dwTypeData), UINT_MAX); + menuiteminfo.cch = (UINT)min(wcslen(menuiteminfo.dwTypeData), (size_t)UINT_MAX); InsertMenuItem((topmenu & MENUIGNORE) ? hMenu : subMenu, (topmenu & MENUIGNORE) ? indexMenu++ : indexSubMenu++, TRUE, &menuiteminfo); if (itemStates & ITEMIS_IGNORED) diff --git a/src/TortoiseShell/stdafx.h b/src/TortoiseShell/stdafx.h index 99bc85798..f4cfe0a64 100644 --- a/src/TortoiseShell/stdafx.h +++ b/src/TortoiseShell/stdafx.h @@ -6,6 +6,11 @@ #include "../targetver.h" +#define NOMINMAX +#include +using std::max; +using std::min; + #define ISOLATION_AWARE_ENABLED 1 #include @@ -28,7 +33,6 @@ #include #include #include -#include #include #define CSTRING_AVAILABLE diff --git a/src/TortoiseUDiff/TortoiseUDiff.cpp b/src/TortoiseUDiff/TortoiseUDiff.cpp index b2ed732e2..de7eb6785 100644 --- a/src/TortoiseUDiff/TortoiseUDiff.cpp +++ b/src/TortoiseUDiff/TortoiseUDiff.cpp @@ -1,4 +1,4 @@ -// TortoiseGit - a Windows shell extension for easy version control +// TortoiseGit - a Windows shell extension for easy version control // Copyright (C) 2011-2017 - TortoiseGit // Copyright (C) 2003-2008, 2010-2012, 2014-2015 - TortoiseSVN @@ -26,7 +26,6 @@ #include "LangDll.h" #include "../version.h" #include "../Utils/CrashReport.h" -#include #include #pragma comment(lib, "comctl32.lib") diff --git a/src/TortoiseUDiff/stdafx.h b/src/TortoiseUDiff/stdafx.h index ba9c2c0ac..e190f4a65 100644 --- a/src/TortoiseUDiff/stdafx.h +++ b/src/TortoiseUDiff/stdafx.h @@ -1,4 +1,4 @@ -// stdafx.h : include file for standard system include files, +// stdafx.h : include file for standard system include files, // or project specific include files that are used frequently, but // are changed infrequently // @@ -7,6 +7,11 @@ #include "../targetver.h" +#define NOMINMAX +#include +using std::max; +using std::min; + // Windows Header Files: #include diff --git a/src/Utils/MiscUI/AnimationManager.cpp b/src/Utils/MiscUI/AnimationManager.cpp index 1bf5a3f30..81d6a846c 100644 --- a/src/Utils/MiscUI/AnimationManager.cpp +++ b/src/Utils/MiscUI/AnimationManager.cpp @@ -20,7 +20,6 @@ #include "stdafx.h" #include "AnimationManager.h" -#include /// Object to handle the timer callback. class CTimerEventHandler : public IUIAnimationTimerEventHandler diff --git a/src/Utils/MiscUI/MyGraph.cpp b/src/Utils/MiscUI/MyGraph.cpp index 8b318503b..72c2bb4e0 100644 --- a/src/Utils/MiscUI/MyGraph.cpp +++ b/src/Utils/MiscUI/MyGraph.cpp @@ -853,7 +853,7 @@ void MyGraph::DrawLegend(CDC& dc) // Get the height of each label. LOGFONT lf = { 0 }; VERIFY(fontLegend.GetLogFont(&lf)); - int nLabelHeight = max(1, abs(lf.lfHeight)); + int nLabelHeight = max(1l, abs(lf.lfHeight)); // Get number of legend entries int nLegendEntries = max(1, GetMaxSeriesSize()); @@ -874,7 +874,7 @@ void MyGraph::DrawLegend(CDC& dc) fontLegend.DeleteObject(); VERIFY(fontLegend.CreatePointFont(optimalPointFontHeight, L"Arial", &dc)); VERIFY(fontLegend.GetLogFont(&lf)); - nLabelHeight = max(1, abs(lf.lfHeight)); + nLabelHeight = max(1l, abs(lf.lfHeight)); } // Calculate maximum number of authors that can be shown with the current label height diff --git a/src/Utils/PathWatcher.cpp b/src/Utils/PathWatcher.cpp index fe9a55912..e973109d2 100644 --- a/src/Utils/PathWatcher.cpp +++ b/src/Utils/PathWatcher.cpp @@ -1,6 +1,6 @@ -// TortoiseGit - a Windows shell extension for easy version control +// TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2013, 2016 - TortoiseGit +// Copyright (C) 2013, 2016, 2018 - TortoiseGit // External Cache Copyright (C) 2007-2012 - TortoiseSVN // This program is free software; you can redistribute it and/or @@ -295,7 +295,7 @@ void CPathWatcher::WorkerThread() pnotify = (PFILE_NOTIFY_INFORMATION)((LPBYTE)pnotify + nOffset); continue; } - buf[min(bufferSize - 1, pdi->m_DirPath.GetLength() + (pnotify->FileNameLength/sizeof(WCHAR)))] = L'\0'; + buf[min((decltype((pnotify->FileNameLength / sizeof(WCHAR)))) bufferSize - 1, pdi->m_DirPath.GetLength() + (pnotify->FileNameLength / sizeof(WCHAR)))] = L'\0'; pnotify = (PFILE_NOTIFY_INFORMATION)((LPBYTE)pnotify + nOffset); CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": change notification: %s\n", buf); { diff --git a/test/Cache/CacheDlg.cpp b/test/Cache/CacheDlg.cpp index 5c1b71dfb..6036e9b9c 100644 --- a/test/Cache/CacheDlg.cpp +++ b/test/Cache/CacheDlg.cpp @@ -1,6 +1,6 @@ // TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2012, 2014-2017 - TortoiseGit +// Copyright (C) 2012, 2014-2018 - TortoiseGit // Copyright (C) 2003-2006, 2009, 2015 - TortoiseSVN // This program is free software; you can redistribute it and/or @@ -131,7 +131,7 @@ UINT CCacheDlg::TestThread() CString sNumber; std::random_device rd; std::mt19937 mt(rd()); - std::uniform_int_distribution dist(0, max(0, m_filelist.GetCount() - 1)); + std::uniform_int_distribution dist(0, max((INT_PTR)0, m_filelist.GetCount() - 1)); std::uniform_int_distribution dist2(0, 9); for (int i=0; i < 1; ++i) { @@ -419,7 +419,7 @@ UINT CCacheDlg::WatchTestThread() CString sNumber; std::random_device rd; std::mt19937 mt(rd()); - std::uniform_int_distribution dist(0, max(0, m_filelist.GetCount() - 1)); + std::uniform_int_distribution dist(0, max((INT_PTR)0, m_filelist.GetCount() - 1)); filepath = m_filelist.GetAt(dist(mt)); GetStatusFromRemoteCache(CTGitPath(m_sRootPath), false); for (int i=0; i < 10000; ++i) diff --git a/test/Cache/stdafx.h b/test/Cache/stdafx.h index b1c5c642d..b08227429 100644 --- a/test/Cache/stdafx.h +++ b/test/Cache/stdafx.h @@ -7,6 +7,11 @@ #include "../../targetver.h" +#define NOMINMAX +#include +using std::min; +using std::max; + #define _AFX_ALL_WARNINGS #include // MFC core and standard components @@ -35,7 +40,6 @@ using namespace ATL; #include #include #include -#include #include #include diff --git a/test/UnitTests/stdafx.h b/test/UnitTests/stdafx.h index e6234c1e7..f038a9d8f 100644 --- a/test/UnitTests/stdafx.h +++ b/test/UnitTests/stdafx.h @@ -7,6 +7,11 @@ #include "../../src\targetver.h" +#define NOMINMAX +#include +using std::min; +using std::max; + #include // MFC core and standard components #include // MFC extensions #include @@ -35,7 +40,6 @@ #include #include #include -#include #include #define __WIN32__ -- 2.11.4.GIT