public inbox for cygwin-cvs@sourceware.org help / color / mirror / Atom feed
From: Takashi Yano <tyan0@sourceware.org> To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin/cygwin-3_3-branch] Cygwin: console: Do not use memcmp() to compare INPUT_RECORD. Date: Sat, 19 Mar 2022 01:07:52 +0000 (GMT) [thread overview] Message-ID: <20220319010752.BE8CC3858D3C@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=8a12474bb5d287d73229270509b49a0c6b8fcabb commit 8a12474bb5d287d73229270509b49a0c6b8fcabb Author: Takashi Yano <takashi.yano@nifty.ne.jp> Date: Sat Mar 19 09:21:04 2022 +0900 Cygwin: console: Do not use memcmp() to compare INPUT_RECORD. - Using memcmp() to compare structure such as INPUT_RECORD is not correct manner because padding may not be initialized. This patch stops to use memcmp() for comparison of INPUT_RECORD. Diff: --- winsup/cygwin/fhandler_console.cc | 41 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc index 1bfe05a99..d2ed15a99 100644 --- a/winsup/cygwin/fhandler_console.cc +++ b/winsup/cygwin/fhandler_console.cc @@ -186,7 +186,9 @@ inrec_eq (const INPUT_RECORD *a, const INPUT_RECORD *b, DWORD n) { for (DWORD i = 0; i < n; i++) { - if (a[i].EventType == KEY_EVENT && b[i].EventType == KEY_EVENT) + if (a[i].EventType != b[i].EventType) + return false; + else if (a[i].EventType == KEY_EVENT) { /* wVirtualKeyCode, wVirtualScanCode and dwControlKeyState of the readback key event may be different from that of written event. Therefore they are ignored. */ @@ -197,8 +199,41 @@ inrec_eq (const INPUT_RECORD *a, const INPUT_RECORD *b, DWORD n) || ak->wRepeatCount != bk->wRepeatCount) return false; } - else if (memcmp (a + i, b + i, sizeof (INPUT_RECORD)) != 0) - return false; + else if (a[i].EventType == MOUSE_EVENT) + { + const MOUSE_EVENT_RECORD *am = &a[i].Event.MouseEvent; + const MOUSE_EVENT_RECORD *bm = &b[i].Event.MouseEvent; + if (am->dwMousePosition.X != bm->dwMousePosition.X + || am->dwMousePosition.Y != bm->dwMousePosition.Y + || am->dwButtonState != bm->dwButtonState + || am->dwControlKeyState != bm->dwControlKeyState + || am->dwEventFlags != bm->dwEventFlags) + return false; + } + else if (a[i].EventType == WINDOW_BUFFER_SIZE_EVENT) + { + const WINDOW_BUFFER_SIZE_RECORD + *aw = &a[i].Event.WindowBufferSizeEvent; + const WINDOW_BUFFER_SIZE_RECORD + *bw = &b[i].Event.WindowBufferSizeEvent; + if (aw->dwSize.X != bw->dwSize.X + || aw->dwSize.Y != bw->dwSize.Y) + return false; + } + else if (a[i].EventType == MENU_EVENT) + { + const MENU_EVENT_RECORD *am = &a[i].Event.MenuEvent; + const MENU_EVENT_RECORD *bm = &b[i].Event.MenuEvent; + if (am->dwCommandId != bm->dwCommandId) + return false; + } + else if (a[i].EventType == FOCUS_EVENT) + { + const FOCUS_EVENT_RECORD *af = &a[i].Event.FocusEvent; + const FOCUS_EVENT_RECORD *bf = &b[i].Event.FocusEvent; + if (af->bSetFocus != bf->bSetFocus) + return false; + } } return true; }
reply other threads:[~2022-03-19 1:07 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220319010752.BE8CC3858D3C@sourceware.org \ --to=tyan0@sourceware.org \ --cc=cygwin-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).