Make code more sanitary

Fix some vulnerable codes detected by VS's analyzing.

Close #10541
This commit is contained in:
Don Ho 2021-09-12 15:22:56 +02:00
parent 36d0d29cc7
commit e5a800722b
30 changed files with 143 additions and 119 deletions

View File

@ -252,7 +252,13 @@ constexpr bool CheckBuildNumber(DWORD buildNumber)
void InitDarkMode()
{
auto RtlGetNtVersionNumbers = reinterpret_cast<fnRtlGetNtVersionNumbers>(GetProcAddress(GetModuleHandle(L"ntdll.dll"), "RtlGetNtVersionNumbers"));
fnRtlGetNtVersionNumbers RtlGetNtVersionNumbers = nullptr;
HMODULE hNtdllModule = GetModuleHandle(L"ntdll.dll");
if (hNtdllModule)
{
RtlGetNtVersionNumbers = reinterpret_cast<fnRtlGetNtVersionNumbers>(GetProcAddress(hNtdllModule, "RtlGetNtVersionNumbers"));
}
if (RtlGetNtVersionNumbers)
{
DWORD major, minor;
@ -278,7 +284,11 @@ void InitDarkMode()
_FlushMenuThemes = reinterpret_cast<fnFlushMenuThemes>(GetProcAddress(hUxtheme, MAKEINTRESOURCEA(136)));
_IsDarkModeAllowedForWindow = reinterpret_cast<fnIsDarkModeAllowedForWindow>(GetProcAddress(hUxtheme, MAKEINTRESOURCEA(137)));
_SetWindowCompositionAttribute = reinterpret_cast<fnSetWindowCompositionAttribute>(GetProcAddress(GetModuleHandleW(L"user32.dll"), "SetWindowCompositionAttribute"));
HMODULE hUser32Module = GetModuleHandleW(L"user32.dll");
if (hUser32Module)
{
_SetWindowCompositionAttribute = reinterpret_cast<fnSetWindowCompositionAttribute>(GetProcAddress(hUser32Module, "SetWindowCompositionAttribute"));
}
if (_OpenNcThemeData &&
_RefreshImmersiveColorPolicyState &&

View File

@ -1068,10 +1068,12 @@ bool isCertificateValidated(const generic_string & fullFilePath, const generic_s
HCERTSTORE hStore = NULL;
HCRYPTMSG hMsg = NULL;
PCCERT_CONTEXT pCertContext = NULL;
BOOL result;
DWORD dwEncoding, dwContentType, dwFormatType;
BOOL result = FALSE;
DWORD dwEncoding = 0;
DWORD dwContentType = 0;
DWORD dwFormatType = 0;
PCMSG_SIGNER_INFO pSignerInfo = NULL;
DWORD dwSignerInfo;
DWORD dwSignerInfo = 0;
CERT_INFO CertInfo;
LPTSTR szName = NULL;

View File

@ -37,8 +37,14 @@ unsigned long Process::runSync(bool isElevationRequired) const
ShExecInfo.lpDirectory = _curDir.c_str();
ShExecInfo.nShow = SW_SHOWNORMAL;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
if (!ShExecInfo.hProcess)
{
// throw exception
throw GetLastErrorAsString(GetLastError());
}
WaitForSingleObject(ShExecInfo.hProcess, INFINITE);
unsigned long exitCode;

View File

@ -257,7 +257,7 @@ INT_PTR CALLBACK RegExtDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lPar
if (i != LB_ERR)
{
const size_t itemNameLen = 32;
TCHAR itemName[itemNameLen + 1];
TCHAR itemName[itemNameLen + 1] = { '\0' };
auto lbTextLen = ::SendDlgItemMessage(_hSelf, LOWORD(wParam), LB_GETTEXTLEN, i, 0);
if (lbTextLen > itemNameLen)
return TRUE;

View File

@ -2458,6 +2458,7 @@ void Notepad_plus::pasteToMarkedLines()
HANDLE clipboardData = ::GetClipboardData(clipFormat);
::GlobalSize(clipboardData);
LPVOID clipboardDataPtr = ::GlobalLock(clipboardData);
if (!clipboardDataPtr) return;
generic_string clipboardStr = (const TCHAR *)clipboardDataPtr;
@ -5768,7 +5769,7 @@ bool Notepad_plus::dumpFiles(const TCHAR * outdir, const TCHAR * fileprefix)
somedirty = true;
const TCHAR * unitext = (docbuf->getUnicodeMode() != uni8Bit)?TEXT("_utf8"):TEXT("");
wsprintf(savePath, TEXT("%s\\%s%03d%s.dump"), outdir, fileprefix, i, unitext);
wsprintf(savePath, TEXT("%s\\%s%03d%s.dump"), outdir, fileprefix, static_cast<int>(i), unitext);
SavingStatus res = MainFileManager.saveBuffer(docbuf->getID(), savePath);
@ -7579,7 +7580,8 @@ void Notepad_plus::showQuote(const QuoteParams* quote) const
params._pCurrentView = _pEditView;
HANDLE hThread = ::CreateThread(NULL, 0, threadTextPlayer, &params, 0, NULL);
::CloseHandle(hThread);
if (hThread)
::CloseHandle(hThread);
}
void Notepad_plus::minimizeDialogs()

View File

@ -785,7 +785,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
case NPPM_GETNAMEPART:
case NPPM_GETEXTPART:
{
TCHAR str[MAX_PATH];
TCHAR str[MAX_PATH] = { '\0' };
// par defaut : NPPM_GETCURRENTDIRECTORY
wcscpy_s(str, _pEditView->getCurrentBuffer()->getFullPathName());
TCHAR* fileStr = str;

View File

@ -772,7 +772,7 @@ namespace NppDarkMode
hFont = reinterpret_cast<HFONT>(SendMessage(hwnd, WM_GETFONT, 0, 0));
}
SelectObject(hdc, hFont);
hOldFont = static_cast<HFONT>(SelectObject(hdc, hFont));
DWORD dtFlags = DT_LEFT; // DT_LEFT is 0
dtFlags |= (nStyle & BS_MULTILINE) ? DT_WORDBREAK : DT_SINGLELINE;

View File

@ -124,7 +124,7 @@ void resolveLinkFile(generic_string& linkFilePath)
{
IShellLink* psl;
WCHAR targetFilePath[MAX_PATH];
WIN32_FIND_DATA wfd;
WIN32_FIND_DATA wfd = {0};
HRESULT hres = CoInitialize(NULL);
if (SUCCEEDED(hres))

View File

@ -229,7 +229,7 @@ struct CmdLineParams
int _column2go = -1;
int _pos2go = -1;
POINT _point;
POINT _point = { 0 };
bool _isPointXValid = false;
bool _isPointYValid = false;
@ -242,7 +242,7 @@ struct CmdLineParams
generic_string _udlName;
generic_string _easterEggName;
unsigned char _quoteType = '\0';
unsigned char _quoteType = 0;
int _ghostTypingSpeed = -1; // -1: initial value 1: slow 2: fast 3: speed of light
CmdLineParams()
@ -294,8 +294,8 @@ struct CmdLineParamsDTO
struct FloatingWindowInfo
{
int _cont;
RECT _pos;
int _cont = 0;
RECT _pos = { 0 };
FloatingWindowInfo(int cont, int x, int y, int w, int h)
: _cont(cont)
@ -544,8 +544,8 @@ struct NewDocDefaultSettings final
struct LangMenuItem final
{
LangType _langType;
int _cmdID;
LangType _langType = L_TEXT;
int _cmdID = -1;
generic_string _langName;
LangMenuItem(LangType lt, int cmdID = 0, const generic_string& langName = TEXT("")):
@ -570,7 +570,7 @@ struct PrintSettings final {
int _footerFontStyle = 0;
int _footerFontSize = 0;
RECT _marge;
RECT _marge = {0};
PrintSettings() {
_marge.left = 0; _marge.top = 0; _marge.right = 0; _marge.bottom = 0;
@ -739,9 +739,9 @@ struct NppGUI final
bool _checkHistoryFiles = false;
RECT _appPos;
RECT _appPos = {0};
RECT _findWindowPos;
RECT _findWindowPos = { 0 };
bool _isMaximized = false;
bool _isMinimizedToTray = false;
@ -919,11 +919,11 @@ struct Lang final
{
LangType _langID = L_TEXT;
generic_string _langName;
const TCHAR *_defaultExtList = nullptr;
const TCHAR *_langKeyWordList[NB_LIST];
const TCHAR *_pCommentLineSymbol = nullptr;
const TCHAR *_pCommentStart = nullptr;
const TCHAR *_pCommentEnd = nullptr;
const TCHAR* _defaultExtList = nullptr;
const TCHAR* _langKeyWordList[NB_LIST];
const TCHAR* _pCommentLineSymbol = nullptr;
const TCHAR* _pCommentStart = nullptr;
const TCHAR* _pCommentEnd = nullptr;
bool _isTabReplacedBySpace = false;
int _tabSize = -1;
@ -992,15 +992,13 @@ struct Lang final
class UserLangContainer final
{
public:
UserLangContainer() :_name(TEXT("new user define")), _ext(TEXT("")), _udlVersion(TEXT(""))
{
init();
UserLangContainer() :_name(TEXT("new user define")), _ext(TEXT("")), _udlVersion(TEXT("")) {
for (int i = 0; i < SCE_USER_KWLIST_TOTAL; ++i) *_keywordLists[i] = '\0';
}
UserLangContainer(const TCHAR *name, const TCHAR *ext, bool isDarkModeTheme, const TCHAR *udlVer):
_name(name), _ext(ext), _isDarkModeTheme(isDarkModeTheme), _udlVersion(udlVer)
{
init();
_name(name), _ext(ext), _isDarkModeTheme(isDarkModeTheme), _udlVersion(udlVer) {
for (int i = 0; i < SCE_USER_KWLIST_TOTAL; ++i) *_keywordLists[i] = '\0';
}
UserLangContainer & operator = (const UserLangContainer & ulc)
@ -1046,13 +1044,13 @@ private:
bool _isDarkModeTheme = false;
TCHAR _keywordLists[SCE_USER_KWLIST_TOTAL][max_char];
bool _isPrefix[SCE_USER_TOTAL_KEYWORD_GROUPS];
bool _isPrefix[SCE_USER_TOTAL_KEYWORD_GROUPS] = {false};
bool _isCaseIgnored;
bool _allowFoldOfComments;
int _forcePureLC;
int _decimalSeparator;
bool _foldCompact;
bool _isCaseIgnored = false;
bool _allowFoldOfComments = false;
int _forcePureLC = PURE_LC_NONE;
int _decimalSeparator = DECSEP_DOT;
bool _foldCompact = false;
// nakama zone
friend class Notepad_plus;
@ -1066,21 +1064,6 @@ private:
friend class SymbolsStyleDialog;
friend class UserDefineDialog;
friend class StylerDlg;
void init()
{
_forcePureLC = PURE_LC_NONE;
_decimalSeparator = DECSEP_DOT;
_foldCompact = false;
_isCaseIgnored = false;
_allowFoldOfComments = false;
for (int i = 0; i < SCE_USER_KWLIST_TOTAL; ++i)
*_keywordLists[i] = '\0';
for (int i = 0; i < SCE_USER_TOTAL_KEYWORD_GROUPS; ++i)
_isPrefix[i] = false;
}
};
#define MAX_EXTERNAL_LEXER_NAME_LEN 16
@ -1150,8 +1133,8 @@ friend class NppParameters;
public:
struct LocalizationDefinition
{
const wchar_t *_langName;
const wchar_t *_xmlFileName;
const wchar_t *_langName = nullptr;
const wchar_t *_xmlFileName = nullptr;
};
bool addLanguageFromXml(const std::wstring& xmlFullPath);
@ -1701,11 +1684,11 @@ private:
NppGUI _nppGUI;
ScintillaViewParams _svp;
Lang *_langList[NB_LANG] = {};
Lang* _langList[NB_LANG] = { nullptr };
int _nbLang = 0;
// Recent File History
generic_string *_LRFileList[NB_MAX_LRF_FILE];
generic_string* _LRFileList[NB_MAX_LRF_FILE] = { nullptr };
int _nbRecentFile = 0;
int _nbMaxRecentFile = 10;
bool _putRecentFileInSubMenu = false;
@ -1715,11 +1698,11 @@ private:
FindHistory _findHistory;
UserLangContainer *_userLangArray[NB_MAX_USER_LANG];
UserLangContainer* _userLangArray[NB_MAX_USER_LANG] = { nullptr };
unsigned char _nbUserLang = 0; // won't be exceeded to 255;
generic_string _userDefineLangsFolderPath;
generic_string _userDefineLangPath;
ExternalLangContainer *_externalLangArray[NB_MAX_EXTERNAL_LANG];
ExternalLangContainer* _externalLangArray[NB_MAX_EXTERNAL_LANG] = { nullptr };
int _nbExternalLang = 0;
CmdLineParamsDTO _cmdLineParams;
@ -1739,7 +1722,7 @@ private:
WNDPROC _transparentFuncAddr = nullptr;
WNDPROC _enableThemeDialogTextureFuncAddr = nullptr;
bool _isLocal;
bool _isLocal = false;
bool _isx64 = false; // by default 32-bit
generic_string _cmdSettingsDir;
@ -1791,19 +1774,19 @@ private:
std::vector<generic_string> _fileBrowserRoot;
generic_string _fileBrowserSelectedItemPath;
Accelerator *_pAccelerator;
ScintillaAccelerator * _pScintAccelerator;
Accelerator* _pAccelerator = nullptr;
ScintillaAccelerator* _pScintAccelerator = nullptr;
FindDlgTabTitiles _findDlgTabTitiles;
bool _asNotepadStyle = false;
winVer _winVersion;
Platform _platForm;
winVer _winVersion = WV_UNKNOWN;
Platform _platForm = PF_UNKNOWN;
NativeLangSpeaker *_pNativeLangSpeaker = nullptr;
COLORREF _currentDefaultBgColor;
COLORREF _currentDefaultFgColor;
COLORREF _currentDefaultBgColor = RGB(0xFF, 0xFF, 0xFF);
COLORREF _currentDefaultFgColor = RGB(0x00, 0x00, 0x00);
generic_string _initialCloudChoice;

View File

@ -1124,7 +1124,7 @@ BufferID FileManager::newEmptyDocument()
generic_string newTitle = ((NppParameters::getInstance()).getNativeLangSpeaker())->getLocalizedStrFromID("tab-untitled-string", UNTITLED_STR);
TCHAR nb[10];
wsprintf(nb, TEXT("%d"), nextUntitledNewNumber());
wsprintf(nb, TEXT("%d"), static_cast<int>(nextUntitledNewNumber()));
newTitle += nb;
Document doc = (Document)_pscratchTilla->execute(SCI_CREATEDOCUMENT); //this already sets a reference for filemanager
@ -1141,7 +1141,7 @@ BufferID FileManager::bufferFromDocument(Document doc, bool dontIncrease, bool d
{
generic_string newTitle = ((NppParameters::getInstance()).getNativeLangSpeaker())->getLocalizedStrFromID("tab-untitled-string", UNTITLED_STR);
TCHAR nb[10];
wsprintf(nb, TEXT("%d"), nextUntitledNewNumber());
wsprintf(nb, TEXT("%d"), static_cast<int>(nextUntitledNewNumber()));
newTitle += nb;
if (!dontRef)

View File

@ -46,7 +46,7 @@ void addText2Combo(const TCHAR * txt2add, HWND hCombo)
generic_string getTextFromCombo(HWND hCombo)
{
TCHAR str[FINDREPLACE_MAXLENGTH];
TCHAR str[FINDREPLACE_MAXLENGTH] = { '\0' };
::SendMessage(hCombo, WM_GETTEXT, FINDREPLACE_MAXLENGTH - 1, reinterpret_cast<LPARAM>(str));
return generic_string(str);
};
@ -429,7 +429,7 @@ void FindReplaceDlg::saveFindHistory()
int FindReplaceDlg::saveComboHistory(int id, int maxcount, vector<generic_string> & strings, bool saveEmpty)
{
TCHAR text[FINDREPLACE_MAXLENGTH];
TCHAR text[FINDREPLACE_MAXLENGTH] = { '\0' };
HWND hCombo = ::GetDlgItem(_hSelf, id);
int count = static_cast<int32_t>(::SendMessage(hCombo, CB_GETCOUNT, 0, 0));
count = min(count, maxcount);
@ -970,6 +970,8 @@ INT_PTR CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
// Change handler of edit element in the comboboxes to support Ctrl+Backspace
COMBOBOXINFO cbinfo = { sizeof(COMBOBOXINFO) };
GetComboBoxInfo(hFindCombo, &cbinfo);
if (!cbinfo.hwndItem) return FALSE;
originalComboEditProc = SetWindowLongPtr(cbinfo.hwndItem, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(comboEditProc));
SetWindowLongPtr(cbinfo.hwndItem, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(cbinfo.hwndCombo));
GetComboBoxInfo(hReplaceCombo, &cbinfo);
@ -4036,7 +4038,7 @@ void Finder::add(FoundInfo fi, SearchResultMarking mi, const TCHAR* foundline)
str += TEXT(" ");
TCHAR lnb[16];
wsprintf(lnb, TEXT("%d"), fi._lineNumber);
wsprintf(lnb, TEXT("%d"), static_cast<int>(fi._lineNumber));
str += lnb;
str += TEXT(": ");
mi._start += static_cast<int32_t>(str.length());

View File

@ -326,7 +326,7 @@ size_t Printer::doPrint(bool justDoIt)
if (!nppGUI._printSettings._printLineNumber)
_pSEView->showMargin(ScintillaEditView::_SC_MARGE_LINENUMBER, false);
size_t pageNum = 1;
int pageNum = 1;
const TCHAR pageVar[] = TEXT("$(CURRENT_PRINTING_PAGE)");
_pSEView->execute(SCI_SETPRINTCOLOURMODE, nppGUI._printSettings._printOption); // setting mode once is enough

View File

@ -3549,7 +3549,9 @@ void ScintillaEditView::runMarkers(bool doHide, size_t searchStart, bool endOfDo
void ScintillaEditView::setTabSettings(Lang *lang)
{
if (lang && lang->_tabSize != -1 && lang->_tabSize != 0)
if (!lang) return;
if (lang->_tabSize != -1 && lang->_tabSize != 0)
{
if (lang->_langID == L_JAVASCRIPT)
{

View File

@ -1134,7 +1134,7 @@ INT_PTR CALLBACK UserDefineDialog::run_dlgProc(UINT message, WPARAM wParam, LPAR
{
if (HIWORD(wParam) == EN_CHANGE)
{
TCHAR ext[extsLenMax];
TCHAR ext[extsLenMax] = { '\0' };
::SendDlgItemMessage(_hSelf, IDC_EXT_EDIT, WM_GETTEXT, extsLenMax, reinterpret_cast<LPARAM>(ext));
_pUserLang->_ext = ext;
return TRUE;

View File

@ -272,8 +272,14 @@ INT_PTR CALLBACK DebugInfoDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM /
}
// Detect WINE
PWINEGETVERSION pWGV = (PWINEGETVERSION)GetProcAddress(GetModuleHandle(TEXT("ntdll.dll")), "wine_get_version");
if (pWGV != NULL)
PWINEGETVERSION pWGV = nullptr;
HMODULE hNtdllModule = GetModuleHandle(L"ntdll.dll");
if (hNtdllModule)
{
pWGV = (PWINEGETVERSION)GetProcAddress(hNtdllModule, "wine_get_version");
}
if (pWGV != nullptr)
{
TCHAR szWINEVersion[32];
generic_sprintf(szWINEVersion, TEXT("%hs"), pWGV());

View File

@ -119,7 +119,7 @@ size_t ListView::findAlphabeticalOrderPos(const generic_string& string2Cmp, Sort
for (size_t i = 0; i < nbItem; ++i)
{
TCHAR str[MAX_PATH];
TCHAR str[MAX_PATH] = { '\0' };
ListView_GetItemText(_hSelf, i, 0, str, sizeof(str));
int res = lstrcmp(string2Cmp.c_str(), str);

View File

@ -568,7 +568,7 @@ int WordStyleDlg::whichTabColourIndex()
if (i == LB_ERR)
return -1;
const size_t styleNameLen = 128;
TCHAR styleName[styleNameLen + 1];
TCHAR styleName[styleNameLen + 1] = { '\0' };
auto lbTextLen = ::SendDlgItemMessage(_hSelf, IDC_STYLES_LIST, LB_GETTEXTLEN, i, 0);
if (lbTextLen > styleNameLen)
return -1;
@ -673,7 +673,8 @@ void WordStyleDlg::updateUserKeywords()
//TCHAR kw[NB_MAX];
auto len = ::SendDlgItemMessage(_hSelf, IDC_USER_KEYWORDS_EDIT, WM_GETTEXTLENGTH, 0, 0);
len += 1;
TCHAR *kw = new TCHAR[len];
TCHAR* kw = new TCHAR[len];
::memset(kw, 0, len * sizeof(TCHAR));
::SendDlgItemMessage(_hSelf, IDC_USER_KEYWORDS_EDIT, WM_GETTEXT, len, reinterpret_cast<LPARAM>(kw));
style._keywords = kw;
@ -833,7 +834,7 @@ void WordStyleDlg::setVisualFromStyleList()
COLORREF c = NppDarkMode::isEnabled() ? NppDarkMode::getLinkTextColor() : RGB(0x00, 0x00, 0xFF);
const size_t strLen = 256;
TCHAR str[strLen + 1];
TCHAR str[strLen + 1] = { '\0' };
str[0] = '\0';
@ -850,7 +851,7 @@ void WordStyleDlg::setVisualFromStyleList()
if (i == LB_ERR)
return;
const size_t styleNameLen = 64;
TCHAR styleName[styleNameLen + 1];
TCHAR styleName[styleNameLen + 1] = { '\0' };
lbTextLen = ::SendDlgItemMessage(_hSelf, IDC_STYLES_LIST, LB_GETTEXTLEN, i, 0);
if (lbTextLen > styleNameLen)
return;

View File

@ -496,7 +496,7 @@ void Gripper::doTabReordering(POINT pt)
}
// select the tab only in source tab window
if ((_hTab == _hTabSource) && (_iItem != -1))
if ((_hTab != nullptr && _hTab == _hTabSource) && (_iItem != -1))
{
::SendMessage(_hTab, TCM_SETCURSEL, _iItem, 0);
}

View File

@ -418,7 +418,7 @@ bool FileBrowser::selectItemFromPath(const generic_string& itemPath) const
bool FileBrowser::selectCurrentEditingFile() const
{
TCHAR currentDocPath[MAX_PATH] = { '0' };
TCHAR currentDocPath[MAX_PATH] = { '\0' };
::SendMessage(_hParent, NPPM_GETFULLCURRENTPATH, MAX_PATH, reinterpret_cast<LPARAM>(currentDocPath));
generic_string currentDocPathStr = currentDocPath;
@ -567,7 +567,7 @@ void FileBrowser::notified(LPNMHDR notification)
}
else if ((notification->hwndFrom == _treeView.getHSelf()))
{
TCHAR textBuffer[MAX_PATH];
TCHAR textBuffer[MAX_PATH] = { '\0' };
TVITEM tvItem;
tvItem.mask = TVIF_TEXT | TVIF_PARAM;
tvItem.pszText = textBuffer;
@ -1068,7 +1068,7 @@ void FileBrowser::addRootFolder(generic_string rootFolderPath)
patterns2Match.push_back(TEXT("*.*"));
TCHAR *label = ::PathFindFileName(rootFolderPath.c_str());
TCHAR rootLabel[MAX_PATH];
TCHAR rootLabel[MAX_PATH] = {'\0'};
wcscpy_s(rootLabel, label);
size_t len = lstrlen(rootLabel);
if (rootLabel[len - 1] == '\\')
@ -1087,7 +1087,7 @@ HTREEITEM FileBrowser::createFolderItemsFromDirStruct(HTREEITEM hParentItem, con
HTREEITEM hFolderItem = nullptr;
if (directoryStructure._parent == nullptr && hParentItem == nullptr)
{
TCHAR rootPath[MAX_PATH];
TCHAR rootPath[MAX_PATH] = { '\0' };
wcscpy_s(rootPath, directoryStructure._rootPath.c_str());
size_t len = lstrlen(rootPath);
if (rootPath[len - 1] == '\\')
@ -1149,7 +1149,7 @@ HTREEITEM FileBrowser::findChildNodeFromName(HTREEITEM parent, const generic_str
hItemNode != NULL;
hItemNode = _treeView.getNextSibling(hItemNode))
{
TCHAR textBuffer[MAX_PATH];
TCHAR textBuffer[MAX_PATH] = { '\0' };
TVITEM tvItem;
tvItem.mask = TVIF_TEXT;
tvItem.pszText = textBuffer;
@ -1309,7 +1309,7 @@ bool FileBrowser::addToTree(FilesToChange & group, HTREEITEM node)
hItemNode != NULL;
hItemNode = _treeView.getNextSibling(hItemNode))
{
TCHAR textBuffer[MAX_PATH];
TCHAR textBuffer[MAX_PATH] = { '\0' };
TVITEM tvItem;
tvItem.mask = TVIF_TEXT;
tvItem.pszText = textBuffer;
@ -1370,7 +1370,7 @@ HTREEITEM FileBrowser::findInTree(const generic_string& rootPath, HTREEITEM node
hItemNode != NULL;
hItemNode = _treeView.getNextSibling(hItemNode))
{
TCHAR textBuffer[MAX_PATH];
TCHAR textBuffer[MAX_PATH] = { '\0' };
TVITEM tvItem;
tvItem.mask = TVIF_TEXT;
tvItem.pszText = textBuffer;
@ -1411,7 +1411,7 @@ std::vector<HTREEITEM> FileBrowser::findInTree(FilesToChange & group, HTREEITEM
hItemNode != NULL;
hItemNode = _treeView.getNextSibling(hItemNode))
{
TCHAR textBuffer[MAX_PATH];
TCHAR textBuffer[MAX_PATH] = {'\0'};
TVITEM tvItem;
tvItem.mask = TVIF_TEXT;
tvItem.pszText = textBuffer;

View File

@ -1732,7 +1732,7 @@ LRESULT CALLBACK GridProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
//count lines
{
int count=1;
TCHAR tbuffer[255];
TCHAR tbuffer[255] = { '\0' };
wcscpy_s(tbuffer,(TCHAR*)lParam);
for(int j=0;j<(int)lstrlen(tbuffer);j++)
{

View File

@ -918,6 +918,7 @@ INT_PTR CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARAM
nbElem = theMacros.size();
HMENU m = reinterpret_cast<HMENU>(::SendMessage(_hParent, NPPM_INTERNAL_GETMENU, 0, 0));
hMenu = ::GetSubMenu(m, MENUINDEX_MACRO);
modifCmd = IDM_SETTING_SHORTCUT_MAPPER_MACRO;
for (size_t i = shortcutIndex; i < nbElem; ++i) //lower the IDs of the remaining items so there are no gaps
{
@ -952,6 +953,7 @@ INT_PTR CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARAM
nbElem = theUserCmds.size();
HMENU m = reinterpret_cast<HMENU>(::SendMessage(_hParent, NPPM_INTERNAL_GETMENU, 0, 0));
hMenu = ::GetSubMenu(m, MENUINDEX_RUN);
modifCmd = IDM_SETTING_SHORTCUT_MAPPER_RUN;
for (size_t i = shortcutIndex; i < nbElem; ++i) //lower the IDs of the remaining items so there are no gaps
{
@ -967,6 +969,8 @@ INT_PTR CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARAM
nppParam.getAccelerator()->updateShortcuts();
nppParam.setShortcutDirty();
if (!hMenu) return FALSE;
// All menu items are shifted up. So we delete the last item
::RemoveMenu(hMenu, posBase + static_cast<int32_t>(nbElem), MF_BYPOSITION);

View File

@ -72,6 +72,9 @@ void Version::setVersionFrom(const generic_string& filePath)
DWORD handle = 0;
DWORD bufferSize = ::GetFileVersionInfoSize(filePath.c_str(), &handle);
if (handle == 0)
return;
if (bufferSize <= 0)
return;

View File

@ -1530,7 +1530,7 @@ INT_PTR CALLBACK MarginsBorderEdgeSubDlg::run_dlgProc(UINT message, WPARAM wPara
{
if (LOWORD(wParam) == IDC_COLUMNPOS_EDIT)
{
TCHAR text[MAX_PATH];
TCHAR text[MAX_PATH] = {'\0'};
::SendDlgItemMessage(_hSelf, IDC_COLUMNPOS_EDIT, WM_GETTEXT, MAX_PATH, reinterpret_cast<LPARAM>(text));
if (str2numberVector(text, svp._edgeMultiColumnPos))
@ -2138,7 +2138,7 @@ INT_PTR CALLBACK DefaultDirectorySubDlg::run_dlgProc(UINT message, WPARAM wParam
{
case IDC_OPENSAVEDIR_ALWAYSON_EDIT:
{
TCHAR inputDir[MAX_PATH];
TCHAR inputDir[MAX_PATH] = { '\0' };
::SendDlgItemMessage(_hSelf, IDC_OPENSAVEDIR_ALWAYSON_EDIT, WM_GETTEXT, MAX_PATH, reinterpret_cast<LPARAM>(inputDir));
wcscpy_s(nppGUI._defaultDir, inputDir);
::ExpandEnvironmentStrings(nppGUI._defaultDir, nppGUI._defaultDirExp, _countof(nppGUI._defaultDirExp));
@ -2988,7 +2988,7 @@ INT_PTR CALLBACK PrintSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM)
::SetDlgItemText(_hSelf, IDC_EDIT_FRIGHT, nppGUI._printSettings._footerRight.c_str());
TCHAR intStr[5];
for (size_t i = 6 ; i < 15 ; ++i)
for (int i = 6 ; i < 15 ; ++i)
{
wsprintf(intStr, TEXT("%d"), i);
::SendDlgItemMessage(_hSelf, IDC_COMBO_HFONTSIZE, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(intStr));
@ -3383,7 +3383,7 @@ INT_PTR CALLBACK BackupSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM l
{
case IDC_BACKUPDIR_EDIT:
{
TCHAR inputDir[MAX_PATH];
TCHAR inputDir[MAX_PATH] = {'\0'};
::SendDlgItemMessage(_hSelf, IDC_BACKUPDIR_EDIT, WM_GETTEXT, MAX_PATH, reinterpret_cast<LPARAM>(inputDir));
nppGUI._backupDir = inputDir;
return TRUE;
@ -4195,14 +4195,14 @@ INT_PTR CALLBACK DelimiterSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
{
case IDC_EDIT_OPENDELIMITER:
{
TCHAR opener[2];
TCHAR opener[2] = { '\0' };
::SendDlgItemMessage(_hSelf, IDC_EDIT_OPENDELIMITER, WM_GETTEXT, MAX_PATH, reinterpret_cast<LPARAM>(opener));
nppGUI._leftmostDelimiter = static_cast<char>(opener[0]);
return TRUE;
}
case IDC_EDIT_CLOSEDELIMITER:
{
TCHAR closer[2];
TCHAR closer[2] = { '\0' };
::SendDlgItemMessage(_hSelf, IDC_EDIT_CLOSEDELIMITER, WM_GETTEXT, MAX_PATH, reinterpret_cast<LPARAM>(closer));
nppGUI._rightmostDelimiter = static_cast<char>(closer[0]);
return TRUE;

View File

@ -664,7 +664,7 @@ void ProjectPanel::notified(LPNMHDR notification)
}
else if ((notification->hwndFrom == _treeView.getHSelf()))
{
TCHAR textBuffer[MAX_PATH];
TCHAR textBuffer[MAX_PATH] = { '\0' };
TVITEM tvItem;
tvItem.mask = TVIF_TEXT | TVIF_PARAM;
tvItem.pszText = textBuffer;

View File

@ -140,10 +140,10 @@ void expandNppEnvironmentStrs(const TCHAR *strSrc, TCHAR *stringDest, size_t str
}
else
{
TCHAR expandedStr[CURRENTWORD_MAXLENGTH];
TCHAR expandedStr[CURRENTWORD_MAXLENGTH] = { '\0' };
if (internalVar == CURRENT_LINE || internalVar == CURRENT_COLUMN)
{
auto lineNumber = ::SendMessage(hWnd, RUNCOMMAND_USER + internalVar, 0, 0);
int lineNumber = static_cast<int>(::SendMessage(hWnd, RUNCOMMAND_USER + internalVar, 0, 0));
wsprintf(expandedStr, TEXT("%d"), lineNumber);
}
else

View File

@ -190,11 +190,16 @@ HGLOBAL StaticDialog::makeRTLResource(int dialogID, DLGTEMPLATE **ppMyDlgTemplat
// Duplicate Dlg Template resource
unsigned long sizeDlg = ::SizeofResource(_hInst, hDialogRC);
HGLOBAL hMyDlgTemplate = ::GlobalAlloc(GPTR, sizeDlg);
if (!hMyDlgTemplate) return nullptr;
*ppMyDlgTemplate = static_cast<DLGTEMPLATE *>(::GlobalLock(hMyDlgTemplate));
if (!*ppMyDlgTemplate) return nullptr;
::memcpy(*ppMyDlgTemplate, pDlgTemplate, sizeDlg);
DLGTEMPLATEEX *pMyDlgTemplateEx = reinterpret_cast<DLGTEMPLATEEX *>(*ppMyDlgTemplate);
DLGTEMPLATEEX* pMyDlgTemplateEx = reinterpret_cast<DLGTEMPLATEEX *>(*ppMyDlgTemplate);
if (!pMyDlgTemplateEx) return nullptr;
if (pMyDlgTemplateEx->signature == 0xFFFF)
pMyDlgTemplateEx->exStyle |= WS_EX_LAYOUTRTL;
else

View File

@ -140,7 +140,7 @@ generic_string TreeView::getItemDisplayName(HTREEITEM Item2Set) const
{
if (!Item2Set)
return TEXT("");
TCHAR textBuffer[MAX_PATH];
TCHAR textBuffer[MAX_PATH] = { '\0' };
TVITEM tvItem;
tvItem.hItem = Item2Set;
tvItem.mask = TVIF_TEXT;
@ -245,7 +245,7 @@ HTREEITEM TreeView::searchSubItemByName(const TCHAR *itemName, HTREEITEM hParent
for ( ; hItem != NULL; hItem = getNextSibling(hItem))
{
TCHAR textBuffer[MAX_PATH];
TCHAR textBuffer[MAX_PATH] = { '\0' };
TVITEM tvItem;
tvItem.hItem = hItem;
tvItem.pszText = textBuffer;
@ -596,7 +596,7 @@ bool TreeView::searchLeafRecusivelyAndBuildTree(HTREEITEM tree2Build, const gene
if (!tree2Search)
return false;
TCHAR textBuffer[MAX_PATH];
TCHAR textBuffer[MAX_PATH] = { '\0' };
TVITEM tvItem;
tvItem.hItem = tree2Search;
tvItem.pszText = textBuffer;
@ -638,7 +638,7 @@ bool TreeView::retrieveFoldingStateTo(TreeStateNode & treeState2Construct, HTREE
if (!treeviewNode)
return false;
TCHAR textBuffer[MAX_PATH];
TCHAR textBuffer[MAX_PATH] = { '\0' };
TVITEM tvItem;
tvItem.hItem = treeviewNode;
tvItem.pszText = textBuffer;

View File

@ -31,8 +31,8 @@
int CALLBACK ListViewCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
sortCompareData* sortData = (sortCompareData*)lParamSort;
TCHAR str1[MAX_PATH];
TCHAR str2[MAX_PATH];
TCHAR str1[MAX_PATH] = { '\0' };
TCHAR str2[MAX_PATH] = { '\0' };
ListView_GetItemText(sortData->hListView, lParam1, sortData->columnIndex, str1, sizeof(str1));
ListView_GetItemText(sortData->hListView, lParam2, sortData->columnIndex, str2, sizeof(str2));
@ -313,7 +313,7 @@ void VerticalFileSwitcher::popupMenuCmd(int cmdID)
{
bool& isExtColumn = NppParameters::getInstance().getNppGUI()._fileSwitcherWithoutExtColumn;
isExtColumn = !isExtColumn;
::CheckMenuItem(_hGlobalMenu, CLMNEXT_ID, MF_BYCOMMAND | isExtColumn ? MF_UNCHECKED : MF_CHECKED);
::CheckMenuItem(_hGlobalMenu, CLMNEXT_ID, MF_BYCOMMAND | (isExtColumn ? MF_UNCHECKED : MF_CHECKED));
reload();
}
break;

View File

@ -208,7 +208,7 @@ public:
int getMenuCmdID() const {return _menuCmdID;};
size_t toKeyDef(size_t index) const {
KeyCombo kc = _keyCombos[index];
int keymod = (kc._isCtrl?SCMOD_CTRL:0) | (kc._isAlt?SCMOD_ALT:0) | (kc._isShift?SCMOD_SHIFT:0);
size_t keymod = (kc._isCtrl ? SCMOD_CTRL : 0) | (kc._isAlt ? SCMOD_ALT : 0) | (kc._isShift ? SCMOD_SHIFT : 0);
return keyTranslate(kc._key) + (keymod << 16);
};

View File

@ -1201,18 +1201,16 @@ bool NativeLangSpeaker::changeDlgLang(HWND hDlg, const char *dlgTagName, char *t
int id;
element->Attribute("id", &id);
HWND hCombo = ::GetDlgItem(hDlg, id);
if (!hCombo) return false;
if (hCombo)
for (TiXmlNodeA *gChildNode = childNode->FirstChildElement("Element");
gChildNode;
gChildNode = gChildNode->NextSibling("Element"))
{
for (TiXmlNodeA *gChildNode = childNode->FirstChildElement("Element");
gChildNode;
gChildNode = gChildNode->NextSibling("Element"))
{
TiXmlElementA *comBoelement = gChildNode->ToElement();
const char *name = comBoelement->Attribute("name");
const wchar_t *nameW = wmc.char2wchar(name, _nativeLangEncoding);
comboElms.push_back(nameW);
}
TiXmlElementA *comBoelement = gChildNode->ToElement();
const char *name = comBoelement->Attribute("name");
const wchar_t *nameW = wmc.char2wchar(name, _nativeLangEncoding);
comboElms.push_back(nameW);
}
size_t count = ::SendMessage(hCombo, CB_GETCOUNT, 0, 0);