From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7868) id 5A1183858D3C; Sat, 19 Mar 2022 01:07:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5A1183858D3C 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: console: Do not use memcmp() to compare INPUT_RECORD. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/master X-Git-Oldrev: 92519e3d0cd71a2ebce70e43e72d22cfee6945ab X-Git-Newrev: 090797e3d3ddae25404584e4e43061911066f685 Message-Id: <20220319010728.5A1183858D3C@sourceware.org> Date: Sat, 19 Mar 2022 01:07:28 +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:28 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D090797e3d3d= dae25404584e4e43061911066f685 commit 090797e3d3ddae25404584e4e43061911066f685 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 fd5f972d8..5625b7be2 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; }