From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7868) id BE8CC3858D3C; Sat, 19 Mar 2022 01:07:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BE8CC3858D3C Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Takashi Yano To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin/cygwin-3_3-branch] Cygwin: console: Do not use memcmp() to compare INPUT_RECORD. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/cygwin-3_3-branch X-Git-Oldrev: 5f10ebc0a76633066bd30c89b715692d68e19f9f X-Git-Newrev: 8a12474bb5d287d73229270509b49a0c6b8fcabb Message-Id: <20220319010752.BE8CC3858D3C@sourceware.org> Date: Sat, 19 Mar 2022 01:07:52 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 19 Mar 2022 01:07:52 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D8a12474bb5d= 287d73229270509b49a0c6b8fcabb commit 8a12474bb5d287d73229270509b49a0c6b8fcabb Author: Takashi Yano Date: Sat Mar 19 09:21:04 2022 +0900 Cygwin: console: Do not use memcmp() to compare INPUT_RECORD. =20 - 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_con= sole.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 =3D 0; i < n; i++) { - if (a[i].EventType =3D=3D KEY_EVENT && b[i].EventType =3D=3D KEY_EVE= NT) + if (a[i].EventType !=3D b[i].EventType) + return false; + else if (a[i].EventType =3D=3D 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 !=3D bk->wRepeatCount) return false; } - else if (memcmp (a + i, b + i, sizeof (INPUT_RECORD)) !=3D 0) - return false; + else if (a[i].EventType =3D=3D MOUSE_EVENT) + { + const MOUSE_EVENT_RECORD *am =3D &a[i].Event.MouseEvent; + const MOUSE_EVENT_RECORD *bm =3D &b[i].Event.MouseEvent; + if (am->dwMousePosition.X !=3D bm->dwMousePosition.X + || am->dwMousePosition.Y !=3D bm->dwMousePosition.Y + || am->dwButtonState !=3D bm->dwButtonState + || am->dwControlKeyState !=3D bm->dwControlKeyState + || am->dwEventFlags !=3D bm->dwEventFlags) + return false; + } + else if (a[i].EventType =3D=3D WINDOW_BUFFER_SIZE_EVENT) + { + const WINDOW_BUFFER_SIZE_RECORD + *aw =3D &a[i].Event.WindowBufferSizeEvent; + const WINDOW_BUFFER_SIZE_RECORD + *bw =3D &b[i].Event.WindowBufferSizeEvent; + if (aw->dwSize.X !=3D bw->dwSize.X + || aw->dwSize.Y !=3D bw->dwSize.Y) + return false; + } + else if (a[i].EventType =3D=3D MENU_EVENT) + { + const MENU_EVENT_RECORD *am =3D &a[i].Event.MenuEvent; + const MENU_EVENT_RECORD *bm =3D &b[i].Event.MenuEvent; + if (am->dwCommandId !=3D bm->dwCommandId) + return false; + } + else if (a[i].EventType =3D=3D FOCUS_EVENT) + { + const FOCUS_EVENT_RECORD *af =3D &a[i].Event.FocusEvent; + const FOCUS_EVENT_RECORD *bf =3D &b[i].Event.FocusEvent; + if (af->bSetFocus !=3D bf->bSetFocus) + return false; + } } return true; }