From 23f8c36900dffeb768d08d26414510b1be74c51c Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Fri, 23 Aug 2019 04:10:16 +0200 Subject: [PATCH] Address code analysis warnings Signed-off-by: Simon Rozman --- include/wxex/appbar.h | 56 +++++++++++++++++++++++----------- include/wxex/crypto.h | 24 +++++++-------- include/wxex/private/tlwgeom.h | 6 ++-- include/wxex/xml.h | 2 +- src/crypto.cpp | 7 +++++ src/xml.cpp | 3 +- 6 files changed, 65 insertions(+), 33 deletions(-) diff --git a/include/wxex/appbar.h b/include/wxex/appbar.h index 8dc4e72..ae19944 100644 --- a/include/wxex/appbar.h +++ b/include/wxex/appbar.h @@ -281,12 +281,12 @@ protected: private: /// \cond internal - inline bool DockAppBar(wxAppBarState state); - inline bool UndockAppBar(); - inline bool RegisterAutoHide(wxAppBarState state); - inline bool UnregisterAutoHide(wxAppBarState state); - inline bool GetDockedRect(wxAppBarState state, LPRECT rect) const; - inline bool GetAutoHideRect(wxAppBarState state, bool bAutoHidden, LPRECT rect) const; + inline _Success_(return != 0) bool DockAppBar(_In_ wxAppBarState state); + inline _Success_(return != 0) bool UndockAppBar(); + inline _Success_(return != 0) bool RegisterAutoHide(_In_ wxAppBarState state); + inline _Success_(return != 0) bool UnregisterAutoHide(_In_ wxAppBarState state); + inline _Success_(return != 0) bool GetDockedRect(_In_ wxAppBarState state, _Out_ LPRECT rect) const; + inline _Success_(return != 0) bool GetAutoHideRect(_In_ wxAppBarState state, _In_ bool bAutoHidden, _Out_ LPRECT rect) const; /// \endcond protected: @@ -516,9 +516,19 @@ inline UINT_PTR wxAppBarGetTaskBarState() template wxAppBar::wxAppBar() : - m_taskbarList(NULL), - m_timerID(0) + m_state(wxABS_UNKNOWN), + m_stateDesired(wxABS_UNKNOWN), + m_flags(0), + m_stateTaskBar(0), + m_timerID(0), + m_taskbarList(NULL) { + m_sizeFloat .cx = -1; + m_sizeFloat .cy = -1; + m_sizeDocked.cx = -1; + m_sizeDocked.cy = -1; + m_sizeMin .cx = -1; + m_sizeMin .cy = -1; } @@ -926,6 +936,9 @@ void wxAppBar::ShowAutoHideAppBar(bool show) GetAutoHideRect(m_state, bHidden, &rcStart); if (bFullDragOn && (rcStart.left != rcEnd.left || rcStart.top != rcEnd.top || rcStart.right != rcEnd.right || rcStart.bottom != rcEnd.bottom)) { + #pragma warning(push) + #pragma warning(disable: 28159) + // Get our starting and ending time. DWORD dwTimeStart = ::GetTickCount(); DWORD dwTimeElapsed; @@ -949,6 +962,8 @@ void wxAppBar::ShowAutoHideAppBar(bool show) wxVERIFY(::SetWindowPos(m_hWnd, NULL, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOZORDER | SWP_NOACTIVATE)); wxVERIFY(::UpdateWindow(m_hWnd)); } + + #pragma warning(pop) } } @@ -1112,15 +1127,16 @@ WXLRESULT wxAppBar::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l if (m_state != m_stateDesired && wxAppBarIsDocked(m_stateDesired)) { wxASSERT(lParam); LPWINDOWPOS lpwndpos = (LPWINDOWPOS)lParam; - - // When about to get docked, fix position and size to avoid Aero Snap interfering with window size. - RECT rect; - GetDockedRect(m_stateDesired, &rect); - lpwndpos->x = rect.left; - lpwndpos->y = rect.top; - lpwndpos->cx = rect.right - rect.left; - lpwndpos->cy = rect.bottom - rect.top; - lpwndpos->flags &= ~(SWP_NOMOVE | SWP_NOSIZE); + if (lpwndpos) { + // When about to get docked, fix position and size to avoid Aero Snap interfering with window size. + RECT rect; + GetDockedRect(m_stateDesired, &rect); + lpwndpos->x = rect.left; + lpwndpos->y = rect.top; + lpwndpos->cx = rect.right - rect.left; + lpwndpos->cy = rect.bottom - rect.top; + lpwndpos->flags &= ~(SWP_NOMOVE | SWP_NOSIZE); + } } return W::MSWWindowProc(message, wParam, lParam); @@ -1439,6 +1455,7 @@ WXLRESULT wxAppBar::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l /// \cond internal template +_Use_decl_annotations_ inline bool wxAppBar::DockAppBar(wxAppBarState state) { wxASSERT(wxAppBarIsDocked(state)); @@ -1454,6 +1471,7 @@ inline bool wxAppBar::DockAppBar(wxAppBarState state) template +_Use_decl_annotations_ inline bool wxAppBar::UndockAppBar() { // Free application bar's space to undock. @@ -1466,6 +1484,7 @@ inline bool wxAppBar::UndockAppBar() template +_Use_decl_annotations_ inline bool wxAppBar::RegisterAutoHide(wxAppBarState state) { wxASSERT(wxAppBarIsDocked(state)); @@ -1498,6 +1517,7 @@ inline bool wxAppBar::RegisterAutoHide(wxAppBarState state) template +_Use_decl_annotations_ inline bool wxAppBar::UnregisterAutoHide(wxAppBarState state) { wxASSERT(wxAppBarIsDocked(state)); @@ -1518,6 +1538,7 @@ inline bool wxAppBar::UnregisterAutoHide(wxAppBarState state) template +_Use_decl_annotations_ inline bool wxAppBar::GetDockedRect(wxAppBarState state, LPRECT rect) const { wxASSERT(wxAppBarIsDocked(state)); @@ -1568,6 +1589,7 @@ inline bool wxAppBar::GetDockedRect(wxAppBarState state, LPRECT rect) const template +_Use_decl_annotations_ inline bool wxAppBar::GetAutoHideRect(wxAppBarState state, bool bAutoHidden, LPRECT rect) const { wxASSERT(wxAppBarIsDocked(state)); diff --git a/include/wxex/crypto.h b/include/wxex/crypto.h index 89b8713..40a7c75 100644 --- a/include/wxex/crypto.h +++ b/include/wxex/crypto.h @@ -142,7 +142,7 @@ public: /// - \c true if hashing succeeded /// - \c false otherwise /// - bool Hash(const void *data, size_t size); + _Success_(return != 0) bool Hash(_In_reads_bytes_(size) const void *data, _In_ size_t size); /// @@ -154,7 +154,7 @@ public: /// - \c true if hashing succeeded /// - \c false otherwise /// - inline bool Hash(const wxMemoryBuffer &data) + inline _Success_(return != 0) bool Hash(_In_ const wxMemoryBuffer &data) { return Hash(data.GetData(), data.GetDataLen()); } @@ -169,7 +169,7 @@ public: /// - \c true if hashing succeeded /// - \c false otherwise /// - inline bool HashAsUTF8(const wxString &str) + inline _Success_(return != 0) bool HashAsUTF8(_In_ const wxString &str) { const wxScopedCharBuffer buf(str.ToUTF8()); return Hash(buf.data(), buf.length()); @@ -185,7 +185,7 @@ public: /// - \c true if hashing succeeded /// - \c false otherwise /// - inline bool HashFile(const wxString &fileName) + inline _Success_(return != 0) bool HashFile(_In_ const wxString &fileName) { wxFFile file(fileName, wxT("rb")); if (file.IsOpened()) { @@ -212,19 +212,19 @@ public: /// - \c true if succeeded /// - \c false otherwise /// - virtual bool GetValue(wxMemoryBuffer &hash); + virtual _Success_(return != 0) bool GetValue(_Out_ wxMemoryBuffer &hash); /// /// Signs the hash using session key /// - /// \param[out] signature Digital signature + /// \param[inout] signature Digital signature /// /// \returns /// - \c true if signing succeeded /// - \c false otherwise /// - bool Sign(wxMemoryBuffer &signature); + _Success_(return != 0) bool Sign(_Inout_ wxMemoryBuffer &signature); /// @@ -262,7 +262,7 @@ public: /// - \c true if succeeded /// - \c false otherwise /// - virtual bool GetValue(wxMemoryBuffer &hash); + virtual _Success_(return != 0) bool GetValue(_Out_ wxMemoryBuffer &hash); }; @@ -312,13 +312,13 @@ public: /// /// Imports private key /// - bool ImportPrivate(wxCryptoSession &session, const void *data, size_t size); + _Success_(return != 0) bool ImportPrivate(_Inout_ wxCryptoSession &session, _In_reads_bytes_(size) const void *data, _In_ size_t size); /// /// Imports public key /// - bool ImportPublic(wxCryptoSession &session, const void *data, size_t size); + _Success_(return != 0) bool ImportPublic(_Inout_ wxCryptoSession &session, _In_reads_bytes_(size) const void *data, _In_ size_t size); }; @@ -334,7 +334,7 @@ public: /// - \c true if verification succeeded and the hash matches /// - \c false otherwise /// -bool WXEXTEND_API wxCryptoVerifySignature(const wxCryptoHash &hash, const void *signature_data, size_t signature_size, const wxCryptoKey &key); +_Success_(return != 0) bool WXEXTEND_API wxCryptoVerifySignature(_In_ const wxCryptoHash &hash, _In_reads_bytes_(signature_size) const void *signature_data, _In_ size_t signature_size, _In_ const wxCryptoKey &key); /// @@ -348,7 +348,7 @@ bool WXEXTEND_API wxCryptoVerifySignature(const wxCryptoHash &hash, const void * /// - \c true if verification succeeded and the hash matches /// - \c false otherwise /// -inline bool wxCryptoVerifySignature(const wxCryptoHash &hash, const wxMemoryBuffer &signature, const wxCryptoKey &key) +inline _Success_(return != 0) bool wxCryptoVerifySignature(_In_ const wxCryptoHash &hash, _In_ const wxMemoryBuffer &signature, _In_ const wxCryptoKey &key) { return wxCryptoVerifySignature(hash, signature.GetData(), signature.GetDataLen(), key); } diff --git a/include/wxex/private/tlwgeom.h b/include/wxex/private/tlwgeom.h index 87f081e..fdbf757 100644 --- a/include/wxex/private/tlwgeom.h +++ b/include/wxex/private/tlwgeom.h @@ -178,6 +178,7 @@ public: HMONITOR hMonitor = ::MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST); wxASSERT_MSG(hMonitor, wxT("error locating monitor")); + _Analysis_assume_(hMonitor); if (!::GetMonitorInfo(hMonitor, &m_mntinfo)) { wxLogLastError(wxS("GetMonitorInfo")); @@ -206,6 +207,7 @@ public: // Get monitor to restore window to. HMONITOR hMonitor = ::MonitorFromRect(&m_mntinfo.rcWork, MONITOR_DEFAULTTONEAREST); wxASSERT_MSG(hMonitor, wxT("error locating monitor")); + _Analysis_assume_(hMonitor); MONITORINFO mntinfo; mntinfo.cbSize = sizeof(mntinfo); if (!::GetMonitorInfo(hMonitor, &mntinfo)) @@ -283,7 +285,7 @@ public: } private: - static bool GetDPI(HWND hWnd, UINT *dpiHorz, UINT *dpiVert) + static bool GetDPI(_In_ HWND hWnd, _Out_ UINT *dpiHorz, _Out_ UINT *dpiVert) { wxASSERT(dpiHorz); wxASSERT(dpiVert); @@ -307,7 +309,7 @@ private: return false; } - static bool GetDPI(HMONITOR hMonitor, UINT *dpiHorz, UINT *dpiVert) + static bool GetDPI(_In_ HMONITOR hMonitor, _Out_ UINT *dpiHorz, _Out_ UINT *dpiVert) { wxASSERT(dpiHorz); wxASSERT(dpiVert); diff --git a/include/wxex/xml.h b/include/wxex/xml.h index a5a114e..c932361 100644 --- a/include/wxex/xml.h +++ b/include/wxex/xml.h @@ -117,6 +117,6 @@ inline wxString wxXmlEscapeAttr(_In_ const wxString& str) /// \param[in] node Root node /// /// -bool WXEXTEND_API wxXmlHashNode(_In_ wxCryptoHash &hash, const wxXmlNode *node); +bool WXEXTEND_API wxXmlHashNode(_In_ wxCryptoHash &hash, _In_ const wxXmlNode *node); /// @} diff --git a/src/crypto.cpp b/src/crypto.cpp index 06f5870..cadae50 100644 --- a/src/crypto.cpp +++ b/src/crypto.cpp @@ -65,6 +65,7 @@ wxCryptoHash::~wxCryptoHash() } +_Use_decl_annotations_ bool wxCryptoHash::Hash(const void *data, size_t size) { wxASSERT_MSG(m_h, wxT("object uninitialized")); @@ -79,6 +80,7 @@ bool wxCryptoHash::Hash(const void *data, size_t size) } +_Use_decl_annotations_ bool wxCryptoHash::GetValue(wxMemoryBuffer &hash) { wxASSERT_MSG(m_h, wxT("object uninitialized")); @@ -106,6 +108,7 @@ bool wxCryptoHash::GetValue(wxMemoryBuffer &hash) } +_Use_decl_annotations_ bool wxCryptoHash::Sign(wxMemoryBuffer &signature) { // Try with the current buffer size first. @@ -146,6 +149,7 @@ wxCryptoHashSHA1::wxCryptoHashSHA1(wxCryptoSession &session) } +_Use_decl_annotations_ bool wxCryptoHashSHA1::GetValue(wxMemoryBuffer &hash) { wxASSERT_MSG(m_h, wxT("object uninitialized")); @@ -182,6 +186,7 @@ wxCryptoKey::~wxCryptoKey() } +_Use_decl_annotations_ bool wxCryptoKey::ImportPrivate(wxCryptoSession &session, const void *data, size_t size) { wxASSERT_MSG(!m_h, wxT("object initialized")); @@ -209,6 +214,7 @@ bool wxCryptoKey::ImportPrivate(wxCryptoSession &session, const void *data, size } +_Use_decl_annotations_ bool wxCryptoKey::ImportPublic(wxCryptoSession &session, const void *data, size_t size) { wxASSERT_MSG(!m_h, wxT("object initialized")); @@ -237,6 +243,7 @@ bool wxCryptoKey::ImportPublic(wxCryptoSession &session, const void *data, size_ // wxCryptoVerifySignature ////////////////////////////////////////////////////////////////////////// +_Use_decl_annotations_ bool WXEXTEND_API wxCryptoVerifySignature(const wxCryptoHash &hash, const void *signature_data, size_t signature_size, const wxCryptoKey &key) { wxASSERT_MSG(hash.IsOk() , wxT("invalid hash")); diff --git a/src/xml.cpp b/src/xml.cpp index 5ac6890..c26f890 100644 --- a/src/xml.cpp +++ b/src/xml.cpp @@ -21,7 +21,8 @@ #include "stdafx.h" -bool WXEXTEND_API wxXmlHashNode(_In_ wxCryptoHash &hash, const wxXmlNode *node) +_Use_decl_annotations_ +bool WXEXTEND_API wxXmlHashNode(wxCryptoHash &hash, const wxXmlNode *node) { wxASSERT_MSG(node, wxT("invalid parameter"));