Fix loads of sizeof() problems with TCHAR (possible buffer overfows by factor 2).

Fix a problem with Incremental search+UTF8 in win9x.

(UTF8 is still problematic in unicode mode.)

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@314 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
harrybharry 2008-09-10 00:32:19 +00:00
parent c2acd30423
commit adba68de00
23 changed files with 112 additions and 88 deletions

View File

@ -3070,7 +3070,7 @@ void Notepad_plus::command(int id)
case IDM_SEARCH_VOLATILE_FINDPREV : case IDM_SEARCH_VOLATILE_FINDPREV :
{ {
TCHAR text2Find[MAX_PATH]; TCHAR text2Find[MAX_PATH];
_pEditView->getGenericSelectedText(text2Find, sizeof(text2Find)); _pEditView->getGenericSelectedText(text2Find, MAX_PATH);
FindOption op; FindOption op;
op._isWholeWord = false; op._isWholeWord = false;
@ -3082,7 +3082,7 @@ void Notepad_plus::command(int id)
{ {
const int strSize = 64; const int strSize = 64;
TCHAR text2Find[strSize]; TCHAR text2Find[strSize];
_pEditView->getGenericSelectedText(text2Find, sizeof(text2Find)); _pEditView->getGenericSelectedText(text2Find, strSize);
FindOption op; FindOption op;
op._isWholeWord = false; op._isWholeWord = false;
@ -4163,7 +4163,7 @@ void Notepad_plus::command(int id)
else if ((id > IDM_LANG_USER) && (id < IDM_LANG_USER_LIMIT)) else if ((id > IDM_LANG_USER) && (id < IDM_LANG_USER_LIMIT))
{ {
TCHAR langName[langNameLenMax]; TCHAR langName[langNameLenMax];
::GetMenuString(_mainMenuHandle, id, langName, sizeof(langName), MF_BYCOMMAND); ::GetMenuString(_mainMenuHandle, id, langName, langNameLenMax, MF_BYCOMMAND);
_pEditView->getCurrentBuffer()->setLangType(L_USER, langName); _pEditView->getCurrentBuffer()->setLangType(L_USER, langName);
} }
else if ((id >= IDM_LANG_EXTERNAL) && (id <= IDM_LANG_EXTERNAL_LIMIT)) else if ((id >= IDM_LANG_EXTERNAL) && (id <= IDM_LANG_EXTERNAL_LIMIT))
@ -4522,7 +4522,7 @@ void Notepad_plus::dropFiles(HDROP hdrop)
for (int i = 0 ; i < filesDropped ; ++i) for (int i = 0 ; i < filesDropped ; ++i)
{ {
TCHAR pathDropped[MAX_PATH]; TCHAR pathDropped[MAX_PATH];
::DragQueryFile(hdrop, i, pathDropped, sizeof(pathDropped)); ::DragQueryFile(hdrop, i, pathDropped, MAX_PATH);
BufferID test = doOpen(pathDropped); BufferID test = doOpen(pathDropped);
if (test != BUFFER_INVALID) if (test != BUFFER_INVALID)
lastOpened = test; lastOpened = test;
@ -5726,7 +5726,8 @@ bool Notepad_plus::doBlockComment(comment_mode currCommentMode)
comment += TEXT(" "); comment += TEXT(" ");
generic_string long_comment = comment; generic_string long_comment = comment;
TCHAR linebuf[1000]; const int linebufferSize = 1000;
TCHAR linebuf[linebufferSize];
size_t comment_length = comment.length(); size_t comment_length = comment.length();
size_t selectionStart = _pEditView->execute(SCI_GETSELECTIONSTART); size_t selectionStart = _pEditView->execute(SCI_GETSELECTIONSTART);
size_t selectionEnd = _pEditView->execute(SCI_GETSELECTIONEND); size_t selectionEnd = _pEditView->execute(SCI_GETSELECTIONEND);
@ -5746,7 +5747,7 @@ bool Notepad_plus::doBlockComment(comment_mode currCommentMode)
int lineStart = _pEditView->execute(SCI_POSITIONFROMLINE, i); int lineStart = _pEditView->execute(SCI_POSITIONFROMLINE, i);
int lineIndent = lineStart; int lineIndent = lineStart;
int lineEnd = _pEditView->execute(SCI_GETLINEENDPOSITION, i); int lineEnd = _pEditView->execute(SCI_GETLINEENDPOSITION, i);
if ((lineEnd - lineIndent) >= static_cast<int>(sizeof(linebuf))) // Avoid buffer size problems if ((lineEnd - lineIndent) >= linebufferSize) // Avoid buffer size problems
continue; continue;
/*if (props.GetInt(comment_at_line_start.c_str())) { /*if (props.GetInt(comment_at_line_start.c_str())) {
GetRange(wEditor, lineIndent, lineEnd, linebuf); GetRange(wEditor, lineIndent, lineEnd, linebuf);
@ -6302,12 +6303,13 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
ExternalLangContainer & externalLangContainer = pNppParam->getELCFromIndex(i); ExternalLangContainer & externalLangContainer = pNppParam->getELCFromIndex(i);
int numLangs = ::GetMenuItemCount(hLangMenu); int numLangs = ::GetMenuItemCount(hLangMenu);
TCHAR buffer[100]; const int bufferSize = 100;
TCHAR buffer[bufferSize];
int x; int x;
for(x = 0; (x == 0 || lstrcmp(externalLangContainer._name, buffer) > 0) && x < numLangs; x++) for(x = 0; (x == 0 || lstrcmp(externalLangContainer._name, buffer) > 0) && x < numLangs; x++)
{ {
::GetMenuString(hLangMenu, x, buffer, sizeof(buffer), MF_BYPOSITION); ::GetMenuString(hLangMenu, x, buffer, bufferSize, MF_BYPOSITION);
} }
::InsertMenu(hLangMenu, x-1, MF_BYPOSITION, IDM_LANG_EXTERNAL + i, externalLangContainer._name); ::InsertMenu(hLangMenu, x-1, MF_BYPOSITION, IDM_LANG_EXTERNAL + i, externalLangContainer._name);
@ -6318,8 +6320,9 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
for (size_t i = 0 ; i < nppGUI._excludedLangList.size() ; i++) for (size_t i = 0 ; i < nppGUI._excludedLangList.size() ; i++)
{ {
int cmdID = pNppParam->langTypeToCommandID(nppGUI._excludedLangList[i]._langType); int cmdID = pNppParam->langTypeToCommandID(nppGUI._excludedLangList[i]._langType);
TCHAR itemName[256]; const int itemSize = 256;
::GetMenuString(hLangMenu, cmdID, itemName, sizeof(itemName), MF_BYCOMMAND); TCHAR itemName[itemSize];
::GetMenuString(hLangMenu, cmdID, itemName, itemSize, MF_BYCOMMAND);
nppGUI._excludedLangList[i]._cmdID = cmdID; nppGUI._excludedLangList[i]._cmdID = cmdID;
nppGUI._excludedLangList[i]._langName = itemName; nppGUI._excludedLangList[i]._langName = itemName;
::DeleteMenu(hLangMenu, cmdID, MF_BYCOMMAND); ::DeleteMenu(hLangMenu, cmdID, MF_BYCOMMAND);

View File

@ -711,10 +711,11 @@ private:
int getLangFromMenuName(const TCHAR * langName) { int getLangFromMenuName(const TCHAR * langName) {
int id = 0; int id = 0;
TCHAR menuLangName[64]; const int menuSize = 64;
TCHAR menuLangName[menuSize];
for ( int i = IDM_LANG_C; i <= IDM_LANG_USER; i++ ) for ( int i = IDM_LANG_C; i <= IDM_LANG_USER; i++ )
if ( ::GetMenuString( _mainMenuHandle, i, menuLangName, sizeof( menuLangName ), MF_BYCOMMAND ) ) if ( ::GetMenuString( _mainMenuHandle, i, menuLangName, menuSize, MF_BYCOMMAND ) )
if ( !lstrcmp( langName, menuLangName ) ) if ( !lstrcmp( langName, menuLangName ) )
{ {
id = i; id = i;
@ -724,7 +725,7 @@ private:
if ( id == 0 ) if ( id == 0 )
{ {
for ( int i = IDM_LANG_USER + 1; i <= IDM_LANG_USER_LIMIT; i++ ) for ( int i = IDM_LANG_USER + 1; i <= IDM_LANG_USER_LIMIT; i++ )
if ( ::GetMenuString( _mainMenuHandle, i, menuLangName, sizeof( menuLangName ), MF_BYCOMMAND ) ) if ( ::GetMenuString( _mainMenuHandle, i, menuLangName, menuSize, MF_BYCOMMAND ) )
if ( !lstrcmp( langName, menuLangName ) ) if ( !lstrcmp( langName, menuLangName ) )
{ {
id = i; id = i;

View File

@ -430,7 +430,7 @@ NppParameters::NppParameters() : _pXmlDoc(NULL),_pXmlUserDoc(NULL), _pXmlUserSty
// Prepare for default path // Prepare for default path
TCHAR nppPath[MAX_PATH]; TCHAR nppPath[MAX_PATH];
::GetModuleFileName(NULL, nppPath, sizeof(nppPath)); ::GetModuleFileName(NULL, nppPath, MAX_PATH);
PathRemoveFileSpec(nppPath); PathRemoveFileSpec(nppPath);
lstrcpy(_nppPath, nppPath); lstrcpy(_nppPath, nppPath);

View File

@ -718,7 +718,8 @@ public :
}; };
UserLangContainer(const TCHAR *name, const TCHAR *ext){ UserLangContainer(const TCHAR *name, const TCHAR *ext){
//si le nom est trop long, on le tranche! //si le nom est trop long, on le tranche!
int minSize = ((sizeof(_name) - 1) < lstrlen(name))?(sizeof(_name) - 1):lstrlen(name); //int minSize = ((sizeof(_name) - 1) < lstrlen(name))?(sizeof(_name) - 1):lstrlen(name);
int minSize = min(langNameLenMax-1, lstrlen(_name));
int i = 0; int i = 0;
for ( ; i < minSize ; i++) for ( ; i < minSize ; i++)
_name[i] = name[i]; _name[i] = name[i];

View File

@ -177,8 +177,9 @@ void AutoCompletion::update(int character)
if (_pEditView->execute(SCI_AUTOCACTIVE) != 0) if (_pEditView->execute(SCI_AUTOCACTIVE) != 0)
return; return;
TCHAR s[64]; const int wordSize = 64;
_pEditView->getWordToCurrentPos(s, sizeof(s)); TCHAR s[wordSize];
_pEditView->getWordToCurrentPos(s, wordSize);
if (lstrlen(s) >= int(nppGUI._autocFromLen)) if (lstrlen(s) >= int(nppGUI._autocFromLen))
{ {

View File

@ -576,13 +576,14 @@ BOOL CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lP
{ {
if (_currentStatus == FINDINFILES_DLG) if (_currentStatus == FINDINFILES_DLG)
{ {
TCHAR filters[256]; const int filterSize = 256;
TCHAR filters[filterSize];
TCHAR directory[MAX_PATH]; TCHAR directory[MAX_PATH];
::GetDlgItemText(_hSelf, IDD_FINDINFILES_FILTERS_COMBO, filters, sizeof(filters)); ::GetDlgItemText(_hSelf, IDD_FINDINFILES_FILTERS_COMBO, filters, filterSize);
addText2Combo(filters, ::GetDlgItem(_hSelf, IDD_FINDINFILES_FILTERS_COMBO)); addText2Combo(filters, ::GetDlgItem(_hSelf, IDD_FINDINFILES_FILTERS_COMBO));
_filters = filters; _filters = filters;
::GetDlgItemText(_hSelf, IDD_FINDINFILES_DIR_COMBO, directory, sizeof(directory)); ::GetDlgItemText(_hSelf, IDD_FINDINFILES_DIR_COMBO, directory, MAX_PATH);
addText2Combo(directory, ::GetDlgItem(_hSelf, IDD_FINDINFILES_DIR_COMBO)); addText2Combo(directory, ::GetDlgItem(_hSelf, IDD_FINDINFILES_DIR_COMBO));
_directory = directory; _directory = directory;
@ -1336,7 +1337,7 @@ void FindReplaceDlg::enableReplaceFunc(bool isEnable)
::MoveWindow(::GetDlgItem(_hSelf, IDCANCEL), pClosePos->left, pClosePos->top, pClosePos->right, pClosePos->bottom, TRUE); ::MoveWindow(::GetDlgItem(_hSelf, IDCANCEL), pClosePos->left, pClosePos->top, pClosePos->right, pClosePos->bottom, TRUE);
TCHAR label[MAX_PATH]; TCHAR label[MAX_PATH];
_tab.getCurrentTitle(label, sizeof(label)); _tab.getCurrentTitle(label, MAX_PATH);
::SetWindowText(_hSelf, label); ::SetWindowText(_hSelf, label);
} }
@ -1378,7 +1379,7 @@ void FindReplaceDlg::enableFindInFilesControls(bool isEnable)
::ShowWindow(::GetDlgItem(_hSelf, IDD_FINDINFILES_INHIDDENDIR_CHECK), isEnable?SW_SHOW:SW_HIDE); ::ShowWindow(::GetDlgItem(_hSelf, IDD_FINDINFILES_INHIDDENDIR_CHECK), isEnable?SW_SHOW:SW_HIDE);
TCHAR label[MAX_PATH]; TCHAR label[MAX_PATH];
_tab.getCurrentTitle(label, sizeof(label)); _tab.getCurrentTitle(label, MAX_PATH);
::SetWindowText(_hSelf, label); ::SetWindowText(_hSelf, label);
} }
@ -1604,7 +1605,7 @@ void FindIncrementDlg::markSelectedTextInc(bool enable, FindOption *opt)
return; return;
TCHAR text2Find[MAX_PATH]; TCHAR text2Find[MAX_PATH];
(*(_pFRDlg->_ppEditView))->getGenericSelectedText(text2Find, sizeof(text2Find), false); //do not expand selection (false) (*(_pFRDlg->_ppEditView))->getGenericSelectedText(text2Find, MAX_PATH, false); //do not expand selection (false)
_pFRDlg->markAllInc(text2Find, opt); _pFRDlg->markAllInc(text2Find, opt);
} }

View File

@ -406,9 +406,18 @@ public :
::SendDlgItemMessage(_hSelf, IDC_INCFINDTEXT, WM_SETTEXT, 0, (LPARAM)txt2find); ::SendDlgItemMessage(_hSelf, IDC_INCFINDTEXT, WM_SETTEXT, 0, (LPARAM)txt2find);
return; return;
} }
WCHAR wchars[256]; const int wideBufferSize = 256;
::MultiByteToWideChar(CP_UTF8, 0, txt2find, -1, wchars, 256 / sizeof(WCHAR)); WCHAR wchars[wideBufferSize];
::SendDlgItemMessageW(_hSelf, IDC_INCFINDTEXT, WM_SETTEXT, 0, (LPARAM)wchars); ::MultiByteToWideChar(CP_UTF8, 0, txt2find, -1, wchars, wideBufferSize);
winVer winVersion = NppParameters::getInstance()->getWinVersion();
if (winVersion <= WV_ME) {
//Cannot simply take txt2find since its UTF8
char ansiBuffer[wideBufferSize]; //Assuming no more than 2 bytes for each wchar (SBCS or DBCS, no UTF8 and sorts)
::WideCharToMultiByte(CP_ACP, 0, wchars, -1, ansiBuffer, wideBufferSize, NULL, NULL);
::SendDlgItemMessageA(_hSelf, IDC_INCFINDTEXT, WM_SETTEXT, 0, (LPARAM)ansiBuffer);
} else {
::SendDlgItemMessageW(_hSelf, IDC_INCFINDTEXT, WM_SETTEXT, 0, (LPARAM)wchars);
}
#endif #endif
} }

View File

@ -230,27 +230,29 @@ size_t Printer::doPrint(bool justDoIt)
frPrint.rc.left += printMarge; frPrint.rc.left += printMarge;
frPrint.rc.right -= printMarge; frPrint.rc.right -= printMarge;
TCHAR headerL[256] = TEXT(""); const int headerSize = 256;
TCHAR headerM[256] = TEXT(""); TCHAR headerL[headerSize] = TEXT("");
TCHAR headerR[256] = TEXT(""); TCHAR headerM[headerSize] = TEXT("");
TCHAR footerL[256] = TEXT(""); TCHAR headerR[headerSize] = TEXT("");
TCHAR footerM[256] = TEXT(""); TCHAR footerL[headerSize] = TEXT("");
TCHAR footerR[256] = TEXT(""); TCHAR footerM[headerSize] = TEXT("");
TCHAR footerR[headerSize] = TEXT("");
const TCHAR shortDateVar[] = TEXT("$(SHORT_DATE)"); const TCHAR shortDateVar[] = TEXT("$(SHORT_DATE)");
const TCHAR longDateVar[] = TEXT("$(LONG_DATE)"); const TCHAR longDateVar[] = TEXT("$(LONG_DATE)");
const TCHAR timeVar[] = TEXT("$(TIME)"); const TCHAR timeVar[] = TEXT("$(TIME)");
TCHAR shortDate[64]; const int bufferSize = 64;
TCHAR longDate[64]; TCHAR shortDate[bufferSize];
TCHAR time[64]; TCHAR longDate[bufferSize];
TCHAR time[bufferSize];
SYSTEMTIME st; SYSTEMTIME st;
::GetLocalTime(&st); ::GetLocalTime(&st);
::GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &st, NULL, shortDate, sizeof(shortDate)); ::GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &st, NULL, shortDate, bufferSize);
::GetDateFormat(LOCALE_USER_DEFAULT, DATE_LONGDATE, &st, NULL, longDate, sizeof(longDate)); ::GetDateFormat(LOCALE_USER_DEFAULT, DATE_LONGDATE, &st, NULL, longDate, bufferSize);
::GetTimeFormat(LOCALE_USER_DEFAULT, TIME_NOSECONDS, &st, NULL, time, sizeof(time)); ::GetTimeFormat(LOCALE_USER_DEFAULT, TIME_NOSECONDS, &st, NULL, time, bufferSize);
if (nppGUI._printSettings.isHeaderPresent()) if (nppGUI._printSettings.isHeaderPresent())
{ {
@ -262,7 +264,7 @@ size_t Printer::doPrint(bool justDoIt)
replaceStr(headerLeftPart, shortDateVar, shortDate); replaceStr(headerLeftPart, shortDateVar, shortDate);
replaceStr(headerLeftPart, longDateVar, longDate); replaceStr(headerLeftPart, longDateVar, longDate);
replaceStr(headerLeftPart, timeVar, time); replaceStr(headerLeftPart, timeVar, time);
expandNppEnvironmentStrs(headerLeftPart.c_str(), headerL, sizeof(headerL), _pdlg.hwndOwner); expandNppEnvironmentStrs(headerLeftPart.c_str(), headerL, headerSize, _pdlg.hwndOwner);
} }
generic_string headerMiddlePart = nppGUI._printSettings._headerMiddle; generic_string headerMiddlePart = nppGUI._printSettings._headerMiddle;
@ -271,7 +273,7 @@ size_t Printer::doPrint(bool justDoIt)
replaceStr(headerMiddlePart, shortDateVar, shortDate); replaceStr(headerMiddlePart, shortDateVar, shortDate);
replaceStr(headerMiddlePart, longDateVar, longDate); replaceStr(headerMiddlePart, longDateVar, longDate);
replaceStr(headerMiddlePart, timeVar, time); replaceStr(headerMiddlePart, timeVar, time);
expandNppEnvironmentStrs(headerMiddlePart.c_str(), headerM, sizeof(headerM), _pdlg.hwndOwner); expandNppEnvironmentStrs(headerMiddlePart.c_str(), headerM, headerSize, _pdlg.hwndOwner);
} }
generic_string headerRightPart = nppGUI._printSettings._headerRight; generic_string headerRightPart = nppGUI._printSettings._headerRight;
@ -280,7 +282,7 @@ size_t Printer::doPrint(bool justDoIt)
replaceStr(headerRightPart, shortDateVar, shortDate); replaceStr(headerRightPart, shortDateVar, shortDate);
replaceStr(headerRightPart, longDateVar, longDate); replaceStr(headerRightPart, longDateVar, longDate);
replaceStr(headerRightPart, timeVar, time); replaceStr(headerRightPart, timeVar, time);
expandNppEnvironmentStrs(headerRightPart.c_str(), headerR, sizeof(headerR), _pdlg.hwndOwner); expandNppEnvironmentStrs(headerRightPart.c_str(), headerR, headerSize, _pdlg.hwndOwner);
} }
} }
@ -295,7 +297,7 @@ size_t Printer::doPrint(bool justDoIt)
replaceStr(footerLeftPart, shortDateVar, shortDate); replaceStr(footerLeftPart, shortDateVar, shortDate);
replaceStr(footerLeftPart, longDateVar, longDate); replaceStr(footerLeftPart, longDateVar, longDate);
replaceStr(footerLeftPart, timeVar, time); replaceStr(footerLeftPart, timeVar, time);
expandNppEnvironmentStrs(footerLeftPart.c_str(), footerL, sizeof(footerL), _pdlg.hwndOwner); expandNppEnvironmentStrs(footerLeftPart.c_str(), footerL, headerSize, _pdlg.hwndOwner);
} }
generic_string footerMiddlePart = nppGUI._printSettings._footerMiddle; generic_string footerMiddlePart = nppGUI._printSettings._footerMiddle;
@ -304,7 +306,7 @@ size_t Printer::doPrint(bool justDoIt)
replaceStr(footerMiddlePart, shortDateVar, shortDate); replaceStr(footerMiddlePart, shortDateVar, shortDate);
replaceStr(footerMiddlePart, longDateVar, longDate); replaceStr(footerMiddlePart, longDateVar, longDate);
replaceStr(footerMiddlePart, timeVar, time); replaceStr(footerMiddlePart, timeVar, time);
expandNppEnvironmentStrs(footerMiddlePart.c_str(), footerM, sizeof(footerM), _pdlg.hwndOwner); expandNppEnvironmentStrs(footerMiddlePart.c_str(), footerM, headerSize, _pdlg.hwndOwner);
} }
generic_string footerRightPart = nppGUI._printSettings._footerRight; generic_string footerRightPart = nppGUI._printSettings._footerRight;
@ -313,7 +315,7 @@ size_t Printer::doPrint(bool justDoIt)
replaceStr(footerRightPart, shortDateVar, shortDate); replaceStr(footerRightPart, shortDateVar, shortDate);
replaceStr(footerRightPart, longDateVar, longDate); replaceStr(footerRightPart, longDateVar, longDate);
replaceStr(footerRightPart, timeVar, time); replaceStr(footerRightPart, timeVar, time);
expandNppEnvironmentStrs(footerRightPart.c_str(), footerR, sizeof(footerR), _pdlg.hwndOwner); expandNppEnvironmentStrs(footerRightPart.c_str(), footerR, headerSize, _pdlg.hwndOwner);
} }
} }

View File

@ -2002,7 +2002,8 @@ void ScintillaEditView::columnReplace(ColumnModeInfo & cmi, int initial, int inc
int nbInit = getNbChiffre(initial, base); int nbInit = getNbChiffre(initial, base);
int nb = max(nbInit, nbEnd); int nb = max(nbInit, nbEnd);
TCHAR str[512]; const int stringSize = 512;
TCHAR str[stringSize];
int totalDiff = 0; int totalDiff = 0;
for (size_t i = 0 ; i < cmi.size() ; i++) for (size_t i = 0 ; i < cmi.size() ; i++)
@ -2013,7 +2014,7 @@ void ScintillaEditView::columnReplace(ColumnModeInfo & cmi, int initial, int inc
cmi[i].first += totalDiff; cmi[i].first += totalDiff;
cmi[i].second += totalDiff; cmi[i].second += totalDiff;
int2str(str, sizeof(str), initial, base, nb, isZeroLeading); int2str(str, stringSize, initial, base, nb, isZeroLeading);
execute(SCI_SETTARGETSTART, cmi[i].first); execute(SCI_SETTARGETSTART, cmi[i].first);
execute(SCI_SETTARGETEND, cmi[i].second); execute(SCI_SETTARGETEND, cmi[i].second);

View File

@ -961,7 +961,7 @@ void SymbolsStyleDialog::listboxsInit()
::SendDlgItemMessage(_hSelf, IDC_SYMBOL_BO3_COMBO, CB_ADDSTRING, 0, (LPARAM)TEXT("")); ::SendDlgItemMessage(_hSelf, IDC_SYMBOL_BO3_COMBO, CB_ADDSTRING, 0, (LPARAM)TEXT(""));
::SendDlgItemMessage(_hSelf, IDC_SYMBOL_BC3_COMBO, CB_ADDSTRING, 0, (LPARAM)TEXT("")); ::SendDlgItemMessage(_hSelf, IDC_SYMBOL_BC3_COMBO, CB_ADDSTRING, 0, (LPARAM)TEXT(""));
for (int i = 0 ; i < int(sizeof(symbolesArray)-1) ; i++) for (int i = 0 ; i < int((sizeof(symbolesArray)/sizeof(TCHAR))-1) ; i++)
{ {
TCHAR s[2]; TCHAR s[2];
s[0] = symbolesArray[i]; s[0] = symbolesArray[i];

View File

@ -50,13 +50,14 @@ BOOL CALLBACK ColumnEditorDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM l
{ {
(*_ppEditView)->execute(SCI_BEGINUNDOACTION); (*_ppEditView)->execute(SCI_BEGINUNDOACTION);
TCHAR str[1024]; const int stringSize = 1024;
TCHAR str[stringSize];
bool isTextMode = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_COL_TEXT_RADIO, BM_GETCHECK, 0, 0)); bool isTextMode = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_COL_TEXT_RADIO, BM_GETCHECK, 0, 0));
if (isTextMode) if (isTextMode)
{ {
::SendDlgItemMessage(_hSelf, IDC_COL_TEXT_EDIT, WM_GETTEXT, sizeof(str), (LPARAM)str); ::SendDlgItemMessage(_hSelf, IDC_COL_TEXT_EDIT, WM_GETTEXT, stringSize, (LPARAM)str);
display(false); display(false);
@ -175,7 +176,7 @@ BOOL CALLBACK ColumnEditorDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM l
/* /*
Calcule generic_string Calcule generic_string
*/ */
int2str(str, sizeof(str), initialNumber, base, nb, isZeroLeading); int2str(str, stringSize, initialNumber, base, nb, isZeroLeading);
initialNumber += increaseNumber; initialNumber += increaseNumber;
if (lineEndCol < cursorCol) if (lineEndCol < cursorCol)

View File

@ -205,7 +205,7 @@ LRESULT URLCtrl::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
// Draw the text! // Draw the text!
TCHAR szWinText[MAX_PATH]; TCHAR szWinText[MAX_PATH];
::GetWindowText(hwnd, szWinText, sizeof szWinText); ::GetWindowText(hwnd, szWinText, MAX_PATH);
::DrawText(hdc, szWinText, -1, &rect, dwDTStyle); ::DrawText(hdc, szWinText, -1, &rect, dwDTStyle);
::SelectObject(hdc, hOld); ::SelectObject(hdc, hOld);
@ -259,7 +259,7 @@ LRESULT URLCtrl::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
else else
{ {
TCHAR szWinText[MAX_PATH]; TCHAR szWinText[MAX_PATH];
::GetWindowText(hwnd, szWinText, sizeof szWinText); ::GetWindowText(hwnd, szWinText, MAX_PATH);
::ShellExecute(NULL, TEXT("open"), szWinText, NULL, NULL, SW_SHOWNORMAL); ::ShellExecute(NULL, TEXT("open"), szWinText, NULL, NULL, SW_SHOWNORMAL);
} }
} }

View File

@ -41,7 +41,7 @@ BOOL CALLBACK ColourStaticTextHooker::colourStaticProc(HWND hwnd, UINT Message,
// Draw the text! // Draw the text!
TCHAR text[MAX_PATH]; TCHAR text[MAX_PATH];
::GetWindowText(hwnd, text, sizeof(text)); ::GetWindowText(hwnd, text, MAX_PATH);
::DrawText(hdc, text, -1, &rect, DT_LEFT); ::DrawText(hdc, text, -1, &rect, DT_LEFT);
::SelectObject(hdc, hOld); ::SelectObject(hdc, hOld);

View File

@ -42,7 +42,7 @@ public:
void create(tTbData * data, bool isRTL = false){ void create(tTbData * data, bool isRTL = false){
StaticDialog::create(_dlgID, isRTL); StaticDialog::create(_dlgID, isRTL);
::GetWindowText(_hSelf, _pluginName, sizeof(_pluginName)); ::GetWindowText(_hSelf, _pluginName, MAX_PATH);
// user information // user information
data->hClient = _hSelf; data->hClient = _hSelf;

View File

@ -343,8 +343,9 @@ BOOL CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARAM lP
} else { } else {
for (size_t i = shortcutIndex ; i < nbElem ; i++) //lower the IDs of the remaining menu items so there are no gaps for (size_t i = shortcutIndex ; i < nbElem ; i++) //lower the IDs of the remaining menu items so there are no gaps
{ {
TCHAR cmdName[64]; const int commandSize = 64;
::GetMenuString(hMenu, cmdID, cmdName, sizeof(cmdName), MF_BYCOMMAND); TCHAR cmdName[commandSize];
::GetMenuString(hMenu, cmdID, cmdName, commandSize, MF_BYCOMMAND);
::ModifyMenu(hMenu, cmdID, MF_BYCOMMAND, cmdID-1, cmdName); //update commandID ::ModifyMenu(hMenu, cmdID, MF_BYCOMMAND, cmdID-1, cmdName); //update commandID
} }
} }

View File

@ -43,7 +43,7 @@ FileDialog::FileDialog(HWND hwnd, HINSTANCE hInst)
_ofn.nMaxCustFilter = 0L; _ofn.nMaxCustFilter = 0L;
_ofn.nFilterIndex = 1L; _ofn.nFilterIndex = 1L;
_ofn.lpstrFile = _fileName; _ofn.lpstrFile = _fileName;
_ofn.nMaxFile = sizeof(_fileName); _ofn.nMaxFile = sizeof(_fileName)/sizeof(TCHAR);
_ofn.lpstrFileTitle = NULL; _ofn.lpstrFileTitle = NULL;
_ofn.nMaxFileTitle = 0; _ofn.nMaxFileTitle = 0;
_ofn.lpstrInitialDir = NULL; _ofn.lpstrInitialDir = NULL;
@ -238,8 +238,8 @@ static BOOL CALLBACK fileDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM
case IDOK : case IDOK :
{ {
HWND fnControl = ::GetDlgItem(hwnd, FileDialog::_dialogFileBoxId); HWND fnControl = ::GetDlgItem(hwnd, FileDialog::_dialogFileBoxId);
TCHAR fn[256]; TCHAR fn[MAX_PATH];
::GetWindowText(fnControl, fn, sizeof(fn)); ::GetWindowText(fnControl, fn, MAX_PATH);
if (*fn == '\0') if (*fn == '\0')
return oldProc(hwnd, message, wParam, lParam); return oldProc(hwnd, message, wParam, lParam);
@ -271,8 +271,8 @@ static TCHAR * get1stExt(TCHAR *ext) { // precondition : ext should be under the
}; };
static generic_string addExt(HWND textCtrl, HWND typeCtrl) { static generic_string addExt(HWND textCtrl, HWND typeCtrl) {
TCHAR fn[256]; TCHAR fn[MAX_PATH];
::GetWindowText(textCtrl, fn, sizeof(fn)); ::GetWindowText(textCtrl, fn, MAX_PATH);
int i = ::SendMessage(typeCtrl, CB_GETCURSEL, 0, 0); int i = ::SendMessage(typeCtrl, CB_GETCURSEL, 0, 0);
TCHAR ext[256]; TCHAR ext[256];

View File

@ -588,7 +588,7 @@ BOOL CALLBACK SettingsDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lPara
case IDC_EDIT_SESSIONFILEEXT: case IDC_EDIT_SESSIONFILEEXT:
{ {
TCHAR sessionExt[MAX_PATH]; TCHAR sessionExt[MAX_PATH];
::SendDlgItemMessage(_hSelf, IDC_EDIT_SESSIONFILEEXT, WM_GETTEXT, sizeof(sessionExt), (LPARAM)sessionExt); ::SendDlgItemMessage(_hSelf, IDC_EDIT_SESSIONFILEEXT, WM_GETTEXT, MAX_PATH, (LPARAM)sessionExt);
nppGUI._definedSessionExt = sessionExt; nppGUI._definedSessionExt = sessionExt;
return TRUE; return TRUE;
} }
@ -1234,9 +1234,10 @@ BOOL CALLBACK PrintSettings2Dlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM
{ {
if (HIWORD(wParam) == EN_CHANGE) if (HIWORD(wParam) == EN_CHANGE)
{ {
TCHAR str[256]; const int stringSize = 256;
TCHAR str[stringSize];
_focusedEditCtrl = LOWORD(wParam); _focusedEditCtrl = LOWORD(wParam);
::GetDlgItemText(_hSelf, _focusedEditCtrl, str, sizeof(str)); ::GetDlgItemText(_hSelf, _focusedEditCtrl, str, stringSize);
::SendDlgItemMessage(_hSelf, IDC_VIEWPANEL_STATIC, WM_SETTEXT, 0, (LPARAM)str); ::SendDlgItemMessage(_hSelf, IDC_VIEWPANEL_STATIC, WM_SETTEXT, 0, (LPARAM)str);
switch (LOWORD(wParam)) switch (LOWORD(wParam))
@ -1277,9 +1278,10 @@ BOOL CALLBACK PrintSettings2Dlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM
} }
else if (HIWORD(wParam) == EN_SETFOCUS) else if (HIWORD(wParam) == EN_SETFOCUS)
{ {
TCHAR str[256]; const int stringSize = 256;
TCHAR str[stringSize];
_focusedEditCtrl = LOWORD(wParam); _focusedEditCtrl = LOWORD(wParam);
::GetDlgItemText(_hSelf, _focusedEditCtrl, str, sizeof(str)); ::GetDlgItemText(_hSelf, _focusedEditCtrl, str, stringSize);
//_colourHooker.setColour(RGB(0, 0, 0xFF)); //_colourHooker.setColour(RGB(0, 0, 0xFF));
::SendDlgItemMessage(_hSelf, IDC_VIEWPANEL_STATIC, WM_SETTEXT, 0, (LPARAM)str); ::SendDlgItemMessage(_hSelf, IDC_VIEWPANEL_STATIC, WM_SETTEXT, 0, (LPARAM)str);
@ -1295,10 +1297,10 @@ BOOL CALLBACK PrintSettings2Dlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM
case IDC_EDIT_FRIGHT : focusedEditStatic = IDC_FR_STATIC; groupStatic = IDC_FGB_STATIC; break; case IDC_EDIT_FRIGHT : focusedEditStatic = IDC_FR_STATIC; groupStatic = IDC_FGB_STATIC; break;
} }
::GetDlgItemText(_hSelf, groupStatic, str, sizeof(str)); ::GetDlgItemText(_hSelf, groupStatic, str, stringSize);
generic_string title = str; generic_string title = str;
title += TEXT(" "); title += TEXT(" ");
::GetDlgItemText(_hSelf, focusedEditStatic, str, sizeof(str)); ::GetDlgItemText(_hSelf, focusedEditStatic, str, stringSize);
title += str; title += str;
title += TEXT(" : "); title += TEXT(" : ");
@ -1379,8 +1381,9 @@ BOOL CALLBACK PrintSettings2Dlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM
wsprintf(toto, TEXT("_selStart = %d\r_selEnd = %d"), _selStart, _selEnd); wsprintf(toto, TEXT("_selStart = %d\r_selEnd = %d"), _selStart, _selEnd);
::MessageBox(NULL, toto, TEXT(""), MB_OK); ::MessageBox(NULL, toto, TEXT(""), MB_OK);
*/ */
TCHAR str[256]; const int stringSize = 256;
::SendDlgItemMessage(_hSelf, _focusedEditCtrl, WM_GETTEXT, sizeof(str), (LPARAM)str); TCHAR str[stringSize];
::SendDlgItemMessage(_hSelf, _focusedEditCtrl, WM_GETTEXT, stringSize, (LPARAM)str);
//::MessageBox(NULL, str, TEXT(""), MB_OK); //::MessageBox(NULL, str, TEXT(""), MB_OK);
generic_string str2Set(str); generic_string str2Set(str);
@ -1461,7 +1464,7 @@ BOOL CALLBACK BackupDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam)
case IDC_BACKUPDIR_EDIT: case IDC_BACKUPDIR_EDIT:
{ {
TCHAR inputDir[MAX_PATH]; TCHAR inputDir[MAX_PATH];
::SendDlgItemMessage(_hSelf, IDC_BACKUPDIR_EDIT, WM_GETTEXT, sizeof(inputDir), (LPARAM)inputDir); ::SendDlgItemMessage(_hSelf, IDC_BACKUPDIR_EDIT, WM_GETTEXT, MAX_PATH, (LPARAM)inputDir);
lstrcpy(nppGUI._backupDir, inputDir); lstrcpy(nppGUI._backupDir, inputDir);
return TRUE; return TRUE;
} }

View File

@ -160,10 +160,10 @@ HINSTANCE Command::run(HWND hWnd)
TCHAR args2Exec[MAX_PATH]; TCHAR args2Exec[MAX_PATH];
extractArgs(cmdPure, args, _cmdLine.c_str()); extractArgs(cmdPure, args, _cmdLine.c_str());
::ExpandEnvironmentStrings(cmdPure, cmdIntermediate, sizeof(cmd2Exec)); ::ExpandEnvironmentStrings(cmdPure, cmdIntermediate, MAX_PATH);
::ExpandEnvironmentStrings(args, argsIntermediate, sizeof(args)); ::ExpandEnvironmentStrings(args, argsIntermediate, MAX_PATH);
expandNppEnvironmentStrs(cmdIntermediate, cmd2Exec, sizeof(cmd2Exec), hWnd); expandNppEnvironmentStrs(cmdIntermediate, cmd2Exec, MAX_PATH, hWnd);
expandNppEnvironmentStrs(argsIntermediate, args2Exec, sizeof(args2Exec), hWnd); expandNppEnvironmentStrs(argsIntermediate, args2Exec, MAX_PATH, hWnd);
return ::ShellExecute(hWnd, TEXT("open"), cmd2Exec, args2Exec, TEXT("."), SW_SHOW); return ::ShellExecute(hWnd, TEXT("open"), cmd2Exec, args2Exec, TEXT("."), SW_SHOW);
} }

View File

@ -78,7 +78,7 @@ public :
TCITEM tie; TCITEM tie;
tie.mask = TCIF_TEXT; tie.mask = TCIF_TEXT;
tie.pszText = (TCHAR *)newName; tie.pszText = (TCHAR *)newName;
tie.cchTextMax = (sizeof(newName)); //tie.cchTextMax = (sizeof(newName)); //this is ignored (besides, 4 bytes for a pointer? =])
TabCtrl_SetItem(_hSelf, index, &tie); TabCtrl_SetItem(_hSelf, index, &tie);
}; };

View File

@ -738,14 +738,15 @@ void TabBarPlus::exchangeItemData(POINT point)
//2. shift their data, and insert the source //2. shift their data, and insert the source
TCITEM itemData_nDraggedTab, itemData_shift; TCITEM itemData_nDraggedTab, itemData_shift;
itemData_nDraggedTab.mask = itemData_shift.mask = TCIF_IMAGE | TCIF_TEXT | TCIF_PARAM; itemData_nDraggedTab.mask = itemData_shift.mask = TCIF_IMAGE | TCIF_TEXT | TCIF_PARAM;
TCHAR str1[256]; const int stringSize = 256;
TCHAR str2[256]; TCHAR str1[stringSize];
TCHAR str2[stringSize];
itemData_nDraggedTab.pszText = str1; itemData_nDraggedTab.pszText = str1;
itemData_nDraggedTab.cchTextMax = (sizeof(str1)); itemData_nDraggedTab.cchTextMax = (stringSize);
itemData_shift.pszText = str2; itemData_shift.pszText = str2;
itemData_shift.cchTextMax = (sizeof(str2)); itemData_shift.cchTextMax = (stringSize);
::SendMessage(_hSelf, TCM_GETITEM, _nTabDragged, reinterpret_cast<LPARAM>(&itemData_nDraggedTab)); ::SendMessage(_hSelf, TCM_GETITEM, _nTabDragged, reinterpret_cast<LPARAM>(&itemData_nDraggedTab));

View File

@ -90,7 +90,7 @@ RECT TaskList::adjustSize()
for (int i = 0 ; i < _nbItem ; i++) for (int i = 0 ; i < _nbItem ; i++)
{ {
TCHAR buf[MAX_PATH]; TCHAR buf[MAX_PATH];
ListView_GetItemText(_hSelf, i, 0, buf, sizeof(buf)); ListView_GetItemText(_hSelf, i, 0, buf, MAX_PATH);
int width = ListView_GetStringWidth(_hSelf, buf); int width = ListView_GetStringWidth(_hSelf, buf);
if (width > (_rc.right - _rc.left)) if (width > (_rc.right - _rc.left))

View File

@ -309,8 +309,9 @@ void getNameStrFromCmd(DWORD cmd, generic_string & str)
else else
{ {
HWND hNotepad_plus = ::FindWindow(Notepad_plus::getClassName(), NULL); HWND hNotepad_plus = ::FindWindow(Notepad_plus::getClassName(), NULL);
TCHAR cmdName[64]; const int commandSize = 64;
int nbChar = ::GetMenuString((HMENU)::SendMessage(hNotepad_plus, NPPM_INTERNAL_GETMENU, 0, 0), cmd, cmdName, sizeof(cmdName), MF_BYCOMMAND); TCHAR cmdName[commandSize];
int nbChar = ::GetMenuString((HMENU)::SendMessage(hNotepad_plus, NPPM_INTERNAL_GETMENU, 0, 0), cmd, cmdName, commandSize, MF_BYCOMMAND);
if (!nbChar) if (!nbChar)
return; return;
bool fin = false; bool fin = false;
@ -635,8 +636,9 @@ void ScintillaAccelerator::updateKey(ScintillaKeyMap skmOld, ScintillaKeyMap skm
void ScintillaAccelerator::updateMenuItemByID(ScintillaKeyMap skm, int id) { void ScintillaAccelerator::updateMenuItemByID(ScintillaKeyMap skm, int id) {
NppParameters *pNppParam = NppParameters::getInstance(); NppParameters *pNppParam = NppParameters::getInstance();
TCHAR cmdName[64]; const int commandSize = 64;
::GetMenuString(_hAccelMenu, id, cmdName, sizeof(cmdName), MF_BYCOMMAND); TCHAR cmdName[commandSize];
::GetMenuString(_hAccelMenu, id, cmdName, commandSize, MF_BYCOMMAND);
int i = 0; int i = 0;
while(cmdName[i] != 0) { while(cmdName[i] != 0) {
if (cmdName[i] == '\t') { if (cmdName[i] == '\t') {

View File

@ -428,9 +428,6 @@ IF NOT EXIST ..\bin\userDefineLang.xml COPY ..\src\userDefineLang.xml ..\bin\use
<File <File
RelativePath="..\src\WinControls\ColourPicker\ColourPopup.cpp"> RelativePath="..\src\WinControls\ColourPicker\ColourPopup.cpp">
</File> </File>
<File
RelativePath="..\src\WinControls\DockingWnd\common_func.cpp">
</File>
<File <File
RelativePath="..\src\WinControls\TabBar\ControlsTab.cpp"> RelativePath="..\src\WinControls\TabBar\ControlsTab.cpp">
</File> </File>