Skip to content

Commit

Permalink
[NOTEPAD] Do type cast to kill C4244 warnings (#5655)
Browse files Browse the repository at this point in the history
- Do type cast to int from SendMessage return value.
- Fix usage of EM_GETSEL and EM_LINEINDEX messages.
CORE-18837
  • Loading branch information
katahiromz authored and errortek committed Sep 7, 2023
1 parent 2a8c2b1 commit c42c27f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
11 changes: 9 additions & 2 deletions base/applications/notepad/dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -865,20 +865,27 @@ VOID DIALOG_GoTo(VOID)
else
ich = (INT)SendMessage(Globals.hEdit, EM_LINEINDEX, GotoData.iLine, 0);

/* EM_LINEINDEX can return -1 on failure */
if (ich < 0)
ich = 0;

/* Move the caret */
SendMessage(Globals.hEdit, EM_SETSEL, ich, ich);
SendMessage(Globals.hEdit, EM_SCROLLCARET, 0, 0);
}

VOID DIALOG_StatusBarUpdateCaretPos(VOID)
{
int line, col;
int line, ich, col;
TCHAR buff[MAX_PATH];
DWORD dwStart, dwSize;

SendMessage(Globals.hEdit, EM_GETSEL, (WPARAM)&dwStart, (LPARAM)&dwSize);
line = SendMessage(Globals.hEdit, EM_LINEFROMCHAR, (WPARAM)dwStart, 0);
col = dwStart - SendMessage(Globals.hEdit, EM_LINEINDEX, (WPARAM)line, 0);
ich = (int)SendMessage(Globals.hEdit, EM_LINEINDEX, (WPARAM)line, 0);

/* EM_LINEINDEX can return -1 on failure */
col = ((ich < 0) ? 0 : (dwStart - ich));

_stprintf(buff, Globals.szStatusBarLineCol, line + 1, col + 1);
SendMessage(Globals.hStatusBar, SB_SETTEXT, SBPART_CURPOS, (LPARAM)buff);
Expand Down
5 changes: 3 additions & 2 deletions base/applications/notepad/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ static VOID NOTEPAD_InitData(HINSTANCE hInstance)
*/
static VOID NOTEPAD_InitMenuPopup(HMENU menu, LPARAM index)
{
DWORD dwStart, dwEnd;
int enable;

UNREFERENCED_PARAMETER(index);
Expand All @@ -280,8 +281,8 @@ static VOID NOTEPAD_InitMenuPopup(HMENU menu, LPARAM index)
SendMessage(Globals.hEdit, EM_CANUNDO, 0, 0) ? MF_ENABLED : MF_GRAYED);
EnableMenuItem(menu, CMD_PASTE,
IsClipboardFormatAvailable(CF_TEXT) ? MF_ENABLED : MF_GRAYED);
enable = (int) SendMessage(Globals.hEdit, EM_GETSEL, 0, 0);
enable = (HIWORD(enable) == LOWORD(enable)) ? MF_GRAYED : MF_ENABLED;
SendMessage(Globals.hEdit, EM_GETSEL, (WPARAM)&dwStart, (LPARAM)&dwEnd);
enable = ((dwStart == dwEnd) ? MF_GRAYED : MF_ENABLED);
EnableMenuItem(menu, CMD_CUT, enable);
EnableMenuItem(menu, CMD_COPY, enable);
EnableMenuItem(menu, CMD_DELETE, enable);
Expand Down

0 comments on commit c42c27f

Please sign in to comment.