Warning/error fixes as per VS2017 code analysis

Closes #4154
This commit is contained in:
Silent 2018-02-05 22:10:36 +01:00 committed by Don HO
parent e403204103
commit 16fa79f057
9 changed files with 24 additions and 22 deletions

View File

@ -766,7 +766,9 @@ COLORREF getCtrlBgColor(HWND hWnd)
generic_string stringToUpper(generic_string strToConvert) generic_string stringToUpper(generic_string strToConvert)
{ {
std::transform(strToConvert.begin(), strToConvert.end(), strToConvert.begin(), ::toupper); std::transform(strToConvert.begin(), strToConvert.end(), strToConvert.begin(),
[](TCHAR ch){ return static_cast<TCHAR>(_totupper(ch)); }
);
return strToConvert; return strToConvert;
} }

View File

@ -58,6 +58,7 @@ distribution.
#include <assert.h> #include <assert.h>
#include <tchar.h>
#include <string> #include <string>
#include "Common.h" #include "Common.h"
@ -176,7 +177,7 @@ protected:
}; };
static const TCHAR* SkipWhiteSpace( const TCHAR* ); static const TCHAR* SkipWhiteSpace( const TCHAR* );
inline static bool IsWhiteSpace( int c ) { return ( isspace( c ) || c == '\n' || c == '\r' ); } inline static bool IsWhiteSpace( int c ) { return ( _istspace( static_cast<TCHAR>(c) ) || c == '\n' || c == '\r' ); }
virtual void StreamOut (TIXML_OSTREAM *) const = 0; virtual void StreamOut (TIXML_OSTREAM *) const = 0;

View File

@ -24,6 +24,7 @@ distribution.
#include <sstream> #include <sstream>
#include <tchar.h>
#include "tinyxml.h" #include "tinyxml.h"
//#define DEBUG_PARSER //#define DEBUG_PARSER
@ -156,7 +157,7 @@ const TCHAR* TiXmlBase::SkipWhiteSpace( const TCHAR* p )
} }
while ( p && *p ) while ( p && *p )
{ {
if ( isspace( *p ) || *p == '\n' || *p =='\r' ) // Still using old rules for white space. if ( _istspace( *p ) || *p == '\n' || *p =='\r' ) // Still using old rules for white space.
++p; ++p;
else else
break; break;
@ -204,10 +205,10 @@ const TCHAR* TiXmlBase::ReadName( const TCHAR* p, TIXML_STRING * name )
// hyphens, or colons. (Colons are valid ony for namespaces, // hyphens, or colons. (Colons are valid ony for namespaces,
// but tinyxml can't tell namespaces from names.) // but tinyxml can't tell namespaces from names.)
if ( p && *p if ( p && *p
&& ( isalpha( (UCHAR) *p ) || *p == '_' ) ) && ( _istalpha( *p ) || *p == '_' ) )
{ {
while( p && *p while( p && *p
&& ( isalnum( (UCHAR ) *p ) && ( _istalnum( *p )
|| *p == '_' || *p == '_'
|| *p == '-' || *p == '-'
|| *p == '.' || *p == '.'
@ -270,7 +271,7 @@ bool TiXmlBase::StringEqual( const TCHAR* p,
return false; return false;
} }
if ( tolower( *p ) == tolower( *tag ) ) if ( _totlower( *p ) == _totlower( *tag ) )
{ {
const TCHAR* q = p; const TCHAR* q = p;
@ -289,7 +290,7 @@ bool TiXmlBase::StringEqual( const TCHAR* p,
} }
else else
{ {
while ( *q && *tag && tolower( *q ) == tolower( *tag ) ) while ( *q && *tag && _totlower( *q ) == _totlower( *tag ) )
{ {
++q; ++q;
++tag; ++tag;
@ -338,7 +339,7 @@ const TCHAR* TiXmlBase::ReadText( const TCHAR* p,
whitespace = true; whitespace = true;
++p; ++p;
} }
else if ( isspace( *p ) ) else if ( _istspace( *p ) )
{ {
whitespace = true; whitespace = true;
++p; ++p;
@ -533,7 +534,7 @@ TiXmlNode* TiXmlNode::Identify( const TCHAR* p )
#endif #endif
returnNode = new TiXmlDeclaration(); returnNode = new TiXmlDeclaration();
} }
else if ( isalpha( *(p+1) ) else if ( _istalpha( *(p+1) )
|| *(p+1) == '_' ) || *(p+1) == '_' )
{ {
#ifdef DEBUG_PARSER #ifdef DEBUG_PARSER
@ -1013,7 +1014,7 @@ const TCHAR* TiXmlAttribute::Parse( const TCHAR* p, TiXmlParsingData* data )
// its best, even without them. // its best, even without them.
value = TEXT(""); value = TEXT("");
while ( p && *p // existence while ( p && *p // existence
&& !isspace( *p ) && *p != '\n' && *p != '\r' // whitespace && !_istspace( *p ) && *p != '\n' && *p != '\r' // whitespace
&& *p != '/' && *p != '>' ) // tag end && *p != '/' && *p != '>' ) // tag end
{ {
value += *p; value += *p;
@ -1126,7 +1127,7 @@ const TCHAR* TiXmlDeclaration::Parse( const TCHAR* p, TiXmlParsingData* data )
else else
{ {
// Read over whatever it is. // Read over whatever it is.
while( p && *p && *p != '>' && !isspace( *p ) ) while( p && *p && *p != '>' && !_istspace( *p ) )
++p; ++p;
} }
} }
@ -1136,7 +1137,7 @@ const TCHAR* TiXmlDeclaration::Parse( const TCHAR* p, TiXmlParsingData* data )
bool TiXmlText::Blank() const bool TiXmlText::Blank() const
{ {
for (size_t i = 0, len = value.length(); i < len; i++) for (size_t i = 0, len = value.length(); i < len; i++)
if ( !isspace( value[i] ) ) if ( !_istspace( value[i] ) )
return false; return false;
return true; return true;
} }

View File

@ -129,7 +129,7 @@ void AnsiCharPanel::insertChar(unsigned char char2insert) const
bool isUnicode = ((*_ppEditView)->execute(SCI_GETCODEPAGE) == SC_CP_UTF8); bool isUnicode = ((*_ppEditView)->execute(SCI_GETCODEPAGE) == SC_CP_UTF8);
if (isUnicode) if (isUnicode)
{ {
MultiByteToWideChar(0, 0, charStr, -1, wCharStr, sizeof(wCharStr)); MultiByteToWideChar(0, 0, charStr, -1, wCharStr, _countof(wCharStr));
WideCharToMultiByte(CP_UTF8, 0, wCharStr, -1, multiByteStr, sizeof(multiByteStr), NULL, NULL); WideCharToMultiByte(CP_UTF8, 0, wCharStr, -1, multiByteStr, sizeof(multiByteStr), NULL, NULL);
} }
else // ANSI else // ANSI
@ -140,7 +140,7 @@ void AnsiCharPanel::insertChar(unsigned char char2insert) const
} }
else else
{ {
MultiByteToWideChar(codepage, 0, charStr, -1, wCharStr, sizeof(wCharStr)); MultiByteToWideChar(codepage, 0, charStr, -1, wCharStr, _countof(wCharStr));
WideCharToMultiByte(CP_UTF8, 0, wCharStr, -1, multiByteStr, sizeof(multiByteStr), NULL, NULL); WideCharToMultiByte(CP_UTF8, 0, wCharStr, -1, multiByteStr, sizeof(multiByteStr), NULL, NULL);
} }
(*_ppEditView)->execute(SCI_REPLACESEL, 0, reinterpret_cast<LPARAM>("")); (*_ppEditView)->execute(SCI_REPLACESEL, 0, reinterpret_cast<LPARAM>(""));

View File

@ -119,7 +119,7 @@ generic_string AsciiListView::getAscii(unsigned char value)
char ascii[2]; char ascii[2];
ascii[0] = value; ascii[0] = value;
ascii[1] = '\0'; ascii[1] = '\0';
MultiByteToWideChar(_codepage, 0, ascii, -1, charStr, sizeof(charStr)); MultiByteToWideChar(_codepage, 0, ascii, -1, charStr, _countof(charStr));
return charStr; return charStr;
} }

View File

@ -177,7 +177,7 @@ LRESULT DockingSplitter::runProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM
if (hookMouse) if (hookMouse)
{ {
::UnhookWindowsHookEx(hookMouse); ::UnhookWindowsHookEx(hookMouse);
::SetCapture(NULL); ::ReleaseCapture();
hookMouse = NULL; hookMouse = NULL;
} }
_isLeftButtonDown = FALSE; _isLeftButtonDown = FALSE;

View File

@ -142,7 +142,7 @@ bool findStrNoCase(const generic_string & strHaystack, const generic_string & st
auto it = std::search( auto it = std::search(
strHaystack.begin(), strHaystack.end(), strHaystack.begin(), strHaystack.end(),
strNeedle.begin(), strNeedle.end(), strNeedle.begin(), strNeedle.end(),
[](char ch1, char ch2){return std::toupper(ch1) == std::toupper(ch2); } [](TCHAR ch1, TCHAR ch2){return _totupper(ch1) == _totupper(ch2); }
); );
return (it != strHaystack.end()); return (it != strHaystack.end());
} }

View File

@ -1359,7 +1359,7 @@ INT_PTR CALLBACK DefaultDirectoryDlg::run_dlgProc(UINT message, WPARAM wParam, L
TCHAR inputDir[MAX_PATH]; TCHAR inputDir[MAX_PATH];
::SendDlgItemMessage(_hSelf, IDC_OPENSAVEDIR_ALWAYSON_EDIT, WM_GETTEXT, MAX_PATH, reinterpret_cast<LPARAM>(inputDir)); ::SendDlgItemMessage(_hSelf, IDC_OPENSAVEDIR_ALWAYSON_EDIT, WM_GETTEXT, MAX_PATH, reinterpret_cast<LPARAM>(inputDir));
lstrcpy(nppGUI._defaultDir, inputDir); lstrcpy(nppGUI._defaultDir, inputDir);
::ExpandEnvironmentStrings(nppGUI._defaultDir, nppGUI._defaultDirExp, 500); ::ExpandEnvironmentStrings(nppGUI._defaultDir, nppGUI._defaultDirExp, _countof(nppGUI._defaultDirExp));
pNppParam->setWorkingDir(nppGUI._defaultDirExp); pNppParam->setWorkingDir(nppGUI._defaultDirExp);
return TRUE; return TRUE;
} }

View File

@ -27,6 +27,7 @@
#include <algorithm> #include <algorithm>
#include <array>
#include "shortcut.h" #include "shortcut.h"
#include "Parameters.h" #include "Parameters.h"
#include "ScintillaEditView.h" #include "ScintillaEditView.h"
@ -472,10 +473,7 @@ INT_PTR CALLBACK Shortcut::run_dlgProc(UINT Message, WPARAM wParam, LPARAM)
// return true if one of CommandShortcuts is deleted. Otherwise false. // return true if one of CommandShortcuts is deleted. Otherwise false.
void Accelerator::updateShortcuts() void Accelerator::updateShortcuts()
{ {
vector<int> incrFindAccIds; const array<unsigned long, 3> incrFindAccIds = { IDM_SEARCH_FINDNEXT, IDM_SEARCH_FINDPREV, IDM_SEARCH_FINDINCREMENT };
incrFindAccIds.push_back(IDM_SEARCH_FINDNEXT);
incrFindAccIds.push_back(IDM_SEARCH_FINDPREV);
incrFindAccIds.push_back(IDM_SEARCH_FINDINCREMENT);
NppParameters *pNppParam = NppParameters::getInstance(); NppParameters *pNppParam = NppParameters::getInstance();