Skip to content

Commit

Permalink
- minor cleanups reported by CppCheck v.1.79
Browse files Browse the repository at this point in the history
- fix exception - reported in notepad2-mod pull request (Crash fixing. rizonesoft#172), which has been rejected there,
  but I was able to reproduce it in VS2017 debug mode (initial defaults for exception handling).
  (XhmikosR/notepad2-mod#172)

- incorporate changes from  notepad2-mod from v.4.2.25.995  to  v.4.2.25.998
  (one fix,  the other changes we have done before already)

- Change shortcuts for the following actions:
  (-) Toggle Transparent Mode:  moved from Ctrl+0  to  Ctrl+Numpad_*
  (x) Reset Zoom: Ctrl+/ change to Ctrl+0      ($v_5.0.26)
  Additional Accelerator Keys, as suggested by (XhmikosR/notepad2-mod#197)
  (+) Toggle Line Comment : in addition to Ctrl+Q add Ctrl+/  with same functionality
  (+) Do Stream Comment : in addition to Ctrl+Shift+Q add Ctrl+Shift+/ with same functionality
  believing new shortcuts are more convenient and more widely used, aren't they?
  • Loading branch information
RaiKoHoff committed Aug 6, 2017
1 parent 74ec34d commit d5e480f
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 53 deletions.
12 changes: 6 additions & 6 deletions scintilla/win32/PlatWin.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -782,14 +782,14 @@ void SurfaceGDI::AlphaRectangle(PRectangle rc, int cornerSize, ColourDesired fil

DWORD valEmpty = dwordFromBGRA(0,0,0,0);
DWORD valFill = dwordFromBGRA(
static_cast<byte>(GetBValue(fill.AsLong()) * alphaFill / 255),
static_cast<byte>(GetGValue(fill.AsLong()) * alphaFill / 255),
static_cast<byte>(GetRValue(fill.AsLong()) * alphaFill / 255),
static_cast<byte>(fill.GetBlue() * alphaFill / 255),
static_cast<byte>(fill.GetGreen() * alphaFill / 255),
static_cast<byte>(fill.GetRed() * alphaFill / 255),
static_cast<byte>(alphaFill));
DWORD valOutline = dwordFromBGRA(
static_cast<byte>(GetBValue(outline.AsLong()) * alphaOutline / 255),
static_cast<byte>(GetGValue(outline.AsLong()) * alphaOutline / 255),
static_cast<byte>(GetRValue(outline.AsLong()) * alphaOutline / 255),
static_cast<byte>(outline.GetBlue() * alphaFill / 255),
static_cast<byte>(outline.GetGreen() * alphaFill / 255),
static_cast<byte>(outline.GetRed() * alphaFill / 255),
static_cast<byte>(alphaOutline));
DWORD *pixels = static_cast<DWORD *>(image);
for (int y=0; y<height; y++) {
Expand Down
6 changes: 0 additions & 6 deletions src/Dlapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,8 @@ static const WCHAR *pDirListProp = L"DirListData";
//
BOOL DirList_Init(HWND hwnd,LPCWSTR pszHeader)
{

HIMAGELIST hil;
SHFILEINFO shfi;
LV_COLUMN lvc;

// Allocate DirListData Property
LPDLDATA lpdl = (LPVOID)GlobalAlloc(GPTR,sizeof(DLDATA));
Expand Down Expand Up @@ -101,11 +99,7 @@ BOOL DirList_Init(HWND hwnd,LPCWSTR pszHeader)
lpdl->hExitThread = CreateEvent(NULL,TRUE,FALSE,NULL);
lpdl->hTerminatedThread = CreateEvent(NULL,TRUE,TRUE,NULL);

lvc;
pszHeader;

return TRUE;

}


Expand Down
29 changes: 15 additions & 14 deletions src/Edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1719,7 +1719,6 @@ void EditTitleCase(HWND hwnd)
UINT cpEdit;
int i;
BOOL bNewWord = TRUE;
BOOL bWordEnd = TRUE;
BOOL bChanged = FALSE;

#ifdef BOOKMARK_EDITION
Expand Down Expand Up @@ -2207,6 +2206,7 @@ void EditHex2Char(HWND hwnd) {
if (SendMessage(hwnd,SCI_GETSELTEXT,0,0) <= COUNTOF(ch)) {

SendMessage(hwnd,SCI_GETSELTEXT,0,(LPARAM)ch);
ch[31] = '\0';

if (StrChrIA(ch,' ') || StrChrIA(ch,'\t') || StrChrIA(ch,'\r') || StrChrIA(ch,'\n') || StrChrIA(ch,'-'))
return;
Expand Down Expand Up @@ -2262,13 +2262,14 @@ void EditModifyNumber(HWND hwnd,BOOL bIncrease) {

if (iSelEnd - iSelStart) {

char chFormat[32] = "";
char chNumber[32];
char chFormat[32] = { '\0' };
char chNumber[32] = { '\0' };
int iNumber;
int iWidth;

if (SendMessage(hwnd,SCI_GETSELTEXT,0,0) <= COUNTOF(chNumber)) {
SendMessage(hwnd,SCI_GETSELTEXT,0,(LPARAM)chNumber);
chNumber[31] = '\0';

if (StrChrIA(chNumber,'-'))
return;
Expand Down Expand Up @@ -2397,7 +2398,7 @@ void EditTabsToSpaces(HWND hwnd,int nTabWidth,BOOL bOnlyIndentingWS)
for (iTextW = 0; iTextW < cchTextW; iTextW++)
{
WCHAR w = pszTextW[iTextW];
if (w == L'\t' && (!bOnlyIndentingWS || bOnlyIndentingWS && bIsLineStart)) {
if (w == L'\t' && (!bOnlyIndentingWS || bIsLineStart)) {
for (j = 0; j < nTabWidth - i % nTabWidth; j++)
pszConvW[cchConvW++] = L' ';
i = 0;
Expand Down Expand Up @@ -2527,7 +2528,7 @@ void EditSpacesToTabs(HWND hwnd,int nTabWidth,BOOL bOnlyIndentingWS)
for (iTextW = 0; iTextW < cchTextW; iTextW++)
{
WCHAR w = pszTextW[iTextW];
if ((w == L' ' || w == L'\t') && (!bOnlyIndentingWS || bOnlyIndentingWS && bIsLineStart)) {
if ((w == L' ' || w == L'\t') && (!bOnlyIndentingWS || bIsLineStart)) {
space[j++] = w;
if (j == nTabWidth - i % nTabWidth || w == L'\t') {
if (j > 1 || pszTextW[iTextW+1] == L' ' || pszTextW[iTextW+1] == L'\t')
Expand Down Expand Up @@ -2814,14 +2815,14 @@ void EditMoveDown(HWND hwnd)
//
void EditModifyLines(HWND hwnd,LPCWSTR pwszPrefix,LPCWSTR pwszAppend)
{
char mszPrefix1[256*3] = "";
char mszPrefix2[256*3] = "";
char mszPrefix1[256*3] = { '\0' };
char mszPrefix2[256*3] = { '\0' };
BOOL bPrefixNum = FALSE;
int iPrefixNum = 0;
int iPrefixNumWidth = 1;
char *pszPrefixNumPad = "";
char mszAppend1[256*3] = "";
char mszAppend2[256*3] = "";
char mszAppend1[256*3] = { '\0' };
char mszAppend2[256*3] = { '\0' };
BOOL bAppendNum = FALSE;
int iAppendNum = 0;
int iAppendNumWidth = 1;
Expand Down Expand Up @@ -3168,7 +3169,7 @@ void EditAlignText(HWND hwnd,int nMode)

else {

char tchLineBuf[BUFSIZE_ALIGN*3] = "";
char tchLineBuf[BUFSIZE_ALIGN*3] = { '\0' };
WCHAR wchLineBuf[BUFSIZE_ALIGN*3] = L"";
WCHAR *pWords[BUFSIZE_ALIGN*3/2];
WCHAR *p = wchLineBuf;
Expand Down Expand Up @@ -3361,8 +3362,8 @@ void EditAlignText(HWND hwnd,int nMode)
//
void EditEncloseSelection(HWND hwnd,LPCWSTR pwszOpen,LPCWSTR pwszClose)
{
char mszOpen[256*3] = "";
char mszClose[256*3] = "";
char mszOpen[256*3] = { '\0' };
char mszClose[256*3] = { '\0' };
int mbcp;

int iSelStart = (int)SendMessage(hwnd,SCI_GETSELECTIONSTART,0,0);
Expand Down Expand Up @@ -3427,7 +3428,7 @@ void EditEncloseSelection(HWND hwnd,LPCWSTR pwszOpen,LPCWSTR pwszClose)
//
void EditToggleLineComments(HWND hwnd,LPCWSTR pwszComment,BOOL bInsertAtStart)
{
char mszComment[256*3] = "";
char mszComment[256*3] = { '\0' };
int cchComment;
int mbcp;
int iAction = 0;
Expand Down Expand Up @@ -4745,7 +4746,7 @@ void EditEnsureSelectionVisible(HWND hwnd)
//
void EditGetExcerpt(HWND hwnd,LPWSTR lpszExcerpt,DWORD cchExcerpt)
{
WCHAR tch[256] = L"";
WCHAR tch[256] = { L'\0' };
WCHAR *p;
DWORD cch = 0;
UINT cpEdit;
Expand Down
9 changes: 6 additions & 3 deletions src/Helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1014,8 +1014,8 @@ void PathRelativeToApp(
//
void PathAbsoluteFromApp(LPWSTR lpszSrc,LPWSTR lpszDest,int cchDest,BOOL bExpandEnv) {

WCHAR wchPath[MAX_PATH];
WCHAR wchResult[MAX_PATH];
WCHAR wchPath[MAX_PATH] = { L'\0'};
WCHAR wchResult[MAX_PATH] = { L'\0'};

if (lpszSrc == NULL) {
ZeroMemory(lpszDest, (cchDest == 0) ? MAX_PATH : cchDest);
Expand All @@ -1026,8 +1026,11 @@ void PathAbsoluteFromApp(LPWSTR lpszSrc,LPWSTR lpszDest,int cchDest,BOOL bExpand
SHGetFolderPath(NULL,CSIDL_PERSONAL,NULL,SHGFP_TYPE_CURRENT,wchPath);
PathAppend(wchPath,lpszSrc+CSTRLEN("%CSIDL:MYDOCUMENTS%"));
}
else
else {
if (lpszSrc) {
lstrcpyn(wchPath,lpszSrc,COUNTOF(wchPath));
}
}

if (bExpandEnv)
ExpandEnvironmentStringsEx(wchPath,COUNTOF(wchPath));
Expand Down
3 changes: 2 additions & 1 deletion src/Helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ extern HINSTANCE g_hInstance;
extern UINT16 g_uWinVer;


#define COUNTOF(ar) (sizeof(ar)/sizeof(ar[0]))
#define UNUSED(expr) (void)(expr)
#define COUNTOF(ar) ARRAYSIZE(ar) //#define COUNTOF(ar) (sizeof(ar)/sizeof(ar[0]))
#define CSTRLEN(s) (COUNTOF(s)-1)


Expand Down
6 changes: 1 addition & 5 deletions src/Notepad3.c
Original file line number Diff line number Diff line change
Expand Up @@ -738,9 +738,6 @@ int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,LPSTR lpCmdLine,int n
OleUninitialize();

return(int)(msg.wParam);

hPrevInst;

}


Expand Down Expand Up @@ -2921,10 +2918,9 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam)
case IDM_EDIT_SWAP:
if (SendMessage(hwndEdit,SCI_GETSELECTIONEND,0,0) -
SendMessage(hwndEdit,SCI_GETSELECTIONSTART,0,0) == 0) {
int iNewPos = -1;
int iPos = (int)SendMessage(hwndEdit,SCI_GETCURRENTPOS,0,0);
SendMessage(hwndEdit,SCI_PASTE,0,0);
iNewPos = (int)SendMessage(hwndEdit,SCI_GETCURRENTPOS,0,0);
int iNewPos = (int)SendMessage(hwndEdit,SCI_GETCURRENTPOS,0,0);
SendMessage(hwndEdit,SCI_SETSEL,iPos,iNewPos);
SendMessage(hwnd,WM_COMMAND,MAKELONG(IDM_EDIT_CLEARCLIPBOARD,1),0);
}
Expand Down
14 changes: 9 additions & 5 deletions src/Notepad3.rc
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ BEGIN
MENUITEM SEPARATOR
MENUITEM "Zoom &In\tCtrl++", IDM_VIEW_ZOOMIN
MENUITEM "Zoom &Out\tCtrl+-", IDM_VIEW_ZOOMOUT
MENUITEM "Reset &Zoom\tCtrl+/", IDM_VIEW_RESETZOOM
MENUITEM "Reset &Zoom\tCtrl+0", IDM_VIEW_RESETZOOM
END
POPUP "&Settings"
BEGIN
Expand All @@ -305,7 +305,7 @@ BEGIN
MENUITEM "Sticky Window &Position", IDM_VIEW_STICKYWINPOS
MENUITEM "&Always On Top\tAlt+T", IDM_VIEW_ALWAYSONTOP
MENUITEM "Minimi&ze To Tray", IDM_VIEW_MINTOTRAY
MENUITEM "Transparent &Mode\tCtrl+0", IDM_VIEW_TRANSPARENT
MENUITEM "Transparent &Mode\tCtrl+Numpad_*", IDM_VIEW_TRANSPARENT
MENUITEM SEPARATOR
MENUITEM "Single &File Instance", IDM_VIEW_SINGLEFILEINSTANCE
MENUITEM "File &Change Notification...\tAlt+F5", IDM_VIEW_CHANGENOTIFY
Expand Down Expand Up @@ -375,7 +375,7 @@ END

IDR_MAINWND ACCELERATORS
BEGIN
"0", IDM_VIEW_TRANSPARENT, VIRTKEY, CONTROL, NOINVERT
"0", IDM_VIEW_RESETZOOM, VIRTKEY, CONTROL, NOINVERT
"0", IDM_FILE_NEWWINDOW2, VIRTKEY, ALT, NOINVERT
"0", IDM_VIEW_WORDWRAPSYMBOLS, VIRTKEY, SHIFT, CONTROL, NOINVERT
"1", CMD_STRINGIFY, VIRTKEY, CONTROL, NOINVERT
Expand Down Expand Up @@ -468,7 +468,6 @@ BEGIN
VK_DELETE, CMD_CTRLDEL, VIRTKEY, CONTROL, NOINVERT
VK_DELETE, IDM_EDIT_CUT, VIRTKEY, SHIFT, NOINVERT
VK_DELETE, IDM_EDIT_DELETELINERIGHT, VIRTKEY, SHIFT, CONTROL, NOINVERT
VK_DIVIDE, IDM_VIEW_RESETZOOM, VIRTKEY, CONTROL, NOINVERT
VK_DOWN, IDM_EDIT_MOVELINEDOWN, VIRTKEY, SHIFT, CONTROL, NOINVERT
VK_ESCAPE, CMD_ESCAPE, VIRTKEY, NOINVERT
VK_ESCAPE, CMD_SHIFTESC, VIRTKEY, SHIFT, NOINVERT
Expand Down Expand Up @@ -513,7 +512,12 @@ BEGIN
VK_F9, IDM_FILE_MANAGEFAV, VIRTKEY, ALT, NOINVERT
VK_F9, CMD_COPYPATHNAME, VIRTKEY, SHIFT, NOINVERT
VK_F9, IDM_EDIT_INSERT_PATHNAME, VIRTKEY, SHIFT, CONTROL, NOINVERT
VK_OEM_2, IDM_VIEW_RESETZOOM, VIRTKEY, CONTROL, NOINVERT
VK_OEM_2, IDM_EDIT_LINECOMMENT, VIRTKEY, CONTROL, NOINVERT
VK_OEM_2, IDM_EDIT_STREAMCOMMENT, VIRTKEY, SHIFT, CONTROL, NOINVERT
VK_DIVIDE, IDM_EDIT_LINECOMMENT, VIRTKEY, CONTROL, NOINVERT
VK_DIVIDE, IDM_EDIT_STREAMCOMMENT, VIRTKEY, SHIFT, CONTROL, NOINVERT
VK_NUMPAD0, IDM_VIEW_RESETZOOM, VIRTKEY, CONTROL, NOINVERT
VK_MULTIPLY, IDM_VIEW_TRANSPARENT, VIRTKEY, CONTROL, NOINVERT
VK_OEM_COMMA, CMD_JUMP2SELSTART, VIRTKEY, CONTROL, NOINVERT
VK_OEM_MINUS, IDM_VIEW_ZOOMOUT, VIRTKEY, CONTROL, NOINVERT
VK_OEM_MINUS, CMD_DECREASENUM, VIRTKEY, CONTROL, ALT, NOINVERT
Expand Down
24 changes: 12 additions & 12 deletions src/Styles.c
Original file line number Diff line number Diff line change
Expand Up @@ -2709,7 +2709,7 @@ void Style_Load()

// default scheme
iDefaultLexer = IniSectionGetInt(pIniSection,L"DefaultScheme",0);
iDefaultLexer = min(max(iDefaultLexer,0),NUMLEXERS-1);
iDefaultLexer = min(max(iDefaultLexer,0),COUNTOF(pLexArray)-1);

// auto select
bAutoSelect = (IniSectionGetInt(pIniSection,L"AutoSelect",1)) ? 1 : 0;
Expand All @@ -2721,7 +2721,7 @@ void Style_Load()
cyStyleSelectDlg = IniSectionGetInt(pIniSection,L"SelectDlgSizeY",0);
cyStyleSelectDlg = max(cyStyleSelectDlg,324);

for (iLexer = 0; iLexer < NUMLEXERS; iLexer++) {
for (iLexer = 0; iLexer < COUNTOF(pLexArray); iLexer++) {
LoadIniSection(pLexArray[iLexer]->pszName,pIniSection,cchIniSection);
if (!IniSectionGetString(pIniSection,L"FileNameExtensions",pLexArray[iLexer]->pszDefExt,
pLexArray[iLexer]->szExtensions,COUNTOF(pLexArray[iLexer]->szExtensions)))
Expand Down Expand Up @@ -2783,7 +2783,7 @@ void Style_Save()
}

ZeroMemory(pIniSection,cchIniSection);
for (iLexer = 0; iLexer < NUMLEXERS; iLexer++) {
for (iLexer = 0; iLexer < COUNTOF(pLexArray); iLexer++) {
IniSectionSetString(pIniSection,L"FileNameExtensions",pLexArray[iLexer]->szExtensions);
i = 0;
while (pLexArray[iLexer]->Styles[i].iStyle != -1) {
Expand Down Expand Up @@ -2826,7 +2826,7 @@ BOOL Style_Import(HWND hwnd)
WCHAR *pIniSection = LocalAlloc(LPTR,sizeof(WCHAR)*32*1024);
int cchIniSection = (int)LocalSize(pIniSection)/sizeof(WCHAR);

for (iLexer = 0; iLexer < NUMLEXERS; iLexer++) {
for (iLexer = 0; iLexer < COUNTOF(pLexArray); iLexer++) {
if (GetPrivateProfileSection(pLexArray[iLexer]->pszName,pIniSection,cchIniSection,szFile)) {
if (!IniSectionGetString(pIniSection,L"FileNameExtensions",pLexArray[iLexer]->pszDefExt,
pLexArray[iLexer]->szExtensions,COUNTOF(pLexArray[iLexer]->szExtensions)))
Expand Down Expand Up @@ -2878,7 +2878,7 @@ BOOL Style_Export(HWND hwnd)
WCHAR *pIniSection = LocalAlloc(LPTR,sizeof(WCHAR)*32*1024);
int cchIniSection = (int)LocalSize(pIniSection)/sizeof(WCHAR);

for (iLexer = 0; iLexer < NUMLEXERS; iLexer++) {
for (iLexer = 0; iLexer < COUNTOF(pLexArray); iLexer++) {
IniSectionSetString(pIniSection,L"FileNameExtensions",pLexArray[iLexer]->szExtensions);
i = 0;
while (pLexArray[iLexer]->Styles[i].iStyle != -1) {
Expand Down Expand Up @@ -3418,7 +3418,7 @@ PEDITLEXER __fastcall Style_MatchLexer(LPCWSTR lpszMatch,BOOL bCheckNames)

if (!bCheckNames) {

for (i = 0; i < NUMLEXERS; i++) {
for (i = 0; i < COUNTOF(pLexArray); i++) {

ZeroMemory(tch,sizeof(WCHAR)*COUNTOF(tch));
lstrcpy(tch,pLexArray[i]->szExtensions);
Expand All @@ -3441,7 +3441,7 @@ PEDITLEXER __fastcall Style_MatchLexer(LPCWSTR lpszMatch,BOOL bCheckNames)
int cch = lstrlen(lpszMatch);
if (cch >= 3) {

for (i = 0; i < NUMLEXERS; i++) {
for (i = 0; i < COUNTOF(pLexArray); i++) {
if (StrCmpNI(pLexArray[i]->pszName,lpszMatch,cch) == 0)
return(pLexArray[i]);
}
Expand Down Expand Up @@ -3625,7 +3625,7 @@ void Style_SetXMLLexer(HWND hwnd)
//
void Style_SetLexerFromID(HWND hwnd,int id)
{
if (id >= 0 && id < NUMLEXERS) {
if (id >= 0 && id < COUNTOF(pLexArray)) {
Style_SetLexer(hwnd,pLexArray[id]);
}
}
Expand Down Expand Up @@ -4448,7 +4448,7 @@ INT_PTR CALLBACK Style_ConfigDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lP
SHGFI_SMALLICON | SHGFI_SYSICONINDEX),TVSIL_NORMAL);

// Add lexers
for (i = 0; i < NUMLEXERS; i++)
for (i = 0; i < COUNTOF(pLexArray); i++)
{
if (!found && lstrcmp(pLexArray[i]->pszName,pLexCurrent->pszName) == 0)
{
Expand Down Expand Up @@ -4959,7 +4959,7 @@ void Style_ConfigDlg(HWND hwnd)

// Backup Styles
c = 0;
for (iLexer = 0; iLexer < NUMLEXERS; iLexer++) {
for (iLexer = 0; iLexer < COUNTOF(pLexArray); iLexer++) {
StyleBackup[c++] = StrDup(pLexArray[iLexer]->szExtensions);
i = 0;
while (pLexArray[iLexer]->Styles[i].iStyle != -1) {
Expand All @@ -4976,7 +4976,7 @@ void Style_ConfigDlg(HWND hwnd)
{
// Restore Styles
c = 0;
for (iLexer = 0; iLexer < NUMLEXERS; iLexer++) {
for (iLexer = 0; iLexer < COUNTOF(pLexArray); iLexer++) {
lstrcpy(pLexArray[iLexer]->szExtensions,StyleBackup[c++]);
i = 0;
while (pLexArray[iLexer]->Styles[i].iStyle != -1) {
Expand Down Expand Up @@ -5075,7 +5075,7 @@ INT_PTR CALLBACK Style_SelectLexerDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPAR
ListView_InsertColumn(hwndLV,0,&lvc);

// Add lexers
for (i = 0; i < NUMLEXERS; i++)
for (i = 0; i < COUNTOF(pLexArray); i++)
Style_AddLexerToListView(hwndLV,pLexArray[i]);

ListView_SetColumnWidth(hwndLV,0,LVSCW_AUTOSIZE_USEHEADER);
Expand Down
2 changes: 1 addition & 1 deletion src/Styles.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ typedef struct _editstyle

typedef struct _keywordlist
{
char *pszKeyWords[9];
char *pszKeyWords[KEYWORDSET_MAX + 1];

} KEYWORDLIST, *PKEYWORDLIST;

Expand Down

0 comments on commit d5e480f

Please sign in to comment.