Commit 104cb383 authored by Vitaly Buka's avatar Vitaly Buka Committed by Commit Bot

Fix union XEvent initialization

C/C++ for "XEvent = {}" promise to zero initialize only the first member of the
union. The tails of larger member can be uninitialized.

Detected with -ftrivial-auto-var-init=pattern.

XEvent member sizes on x86_64
40 xany
96 xkey
96 xbutton
96 xmotion
104 xcrossing
48 xfocus
64 xexpose
72 xgraphicsexpose
48 xnoexpose
48 xvisibility
72 xcreatewindow
48 xdestroywindow
56 xunmap
56 xmap
48 xmaprequest
72 xreparent
88 xconfigure
56 xgravity
48 xresizerequest
96 xconfigurerequest
56 xcirculate
56 xcirculaterequest
64 xproperty
56 xselectionclear
80 xselectionrequest
72 xselection
56 xcolormap
96 xclient
56 xmapping
40 xerror
72 xkeymap
40 xgeneric
56 xcookie
192 pad

Bug: 977230

Change-Id: I7838e5f68b6320e067f9c446222a38fdcd35bdd8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1842505Reviewed-by: default avatarThomas Anderson <thomasanderson@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Commit-Queue: Vitaly Buka <vitalybuka@chromium.org>
Cr-Commit-Position: refs/heads/master@{#703384}
parent 7968374c
......@@ -60,7 +60,8 @@ void GtkEventLoopX11::ProcessGdkEventKey(const GdkEventKey& gdk_event_key) {
// corresponding key event in the X event queue. So we have to handle this
// case. ibus-gtk is used through gtk-immodule to support IMEs.
XEvent x_event = {0};
XEvent x_event;
x_event.xkey = {};
x_event.xkey.type =
gdk_event_key.type == GDK_KEY_PRESS ? KeyPress : KeyRelease;
x_event.xkey.send_event = gdk_event_key.send_event;
......
......@@ -66,7 +66,8 @@ class UIControlsX11 : public UIControlsAura {
bool alt,
bool command,
base::OnceClosure closure) override {
XEvent xevent = {0};
XEvent xevent;
xevent.xkey = {};
xevent.xkey.type = KeyPress;
if (control)
SetKeycodeAndSendThenMask(&xevent, XK_Control_L, ControlMask);
......@@ -119,7 +120,8 @@ class UIControlsX11 : public UIControlsAura {
// current mouse position as a result of XGrabPointer()
host_->window()->MoveCursorTo(root_location);
} else {
XEvent xevent = {0};
XEvent xevent;
xevent.xmotion = {};
XMotionEvent* xmotion = &xevent.xmotion;
xmotion->type = MotionNotify;
xmotion->x = root_location.x();
......@@ -142,7 +144,8 @@ class UIControlsX11 : public UIControlsAura {
int button_state,
base::OnceClosure closure,
int accelerator_state) override {
XEvent xevent = {0};
XEvent xevent;
xevent.xbutton = {};
XButtonEvent* xbutton = &xevent.xbutton;
gfx::Point mouse_loc = Env::GetInstance()->last_mouse_location();
aura::client::ScreenPositionClient* screen_position_client =
......
......@@ -581,7 +581,8 @@ KeyboardCode KeyboardCodeFromXKeyEvent(const XEvent* xev) {
// 8. If not found, fallback to find with the hardware code in US layout.
KeySym keysym = NoSymbol;
XEvent xkeyevent = {0};
XEvent xkeyevent;
xkeyevent.xkey = {};
if (xev->type == GenericEvent) {
// Convert the XI2 key event into a core key event so that we can
// continue to use XLookupString() until crbug.com/367732 is complete.
......@@ -962,7 +963,8 @@ DomCode CodeFromXEvent(const XEvent* xev) {
}
uint16_t GetCharacterFromXEvent(const XEvent* xev) {
XEvent xkeyevent = {0};
XEvent xkeyevent;
xkeyevent.xkey = {};
const XKeyEvent* xkey = NULL;
if (xev->type == GenericEvent) {
// Convert the XI2 key event into a core key event so that we can
......@@ -978,7 +980,8 @@ uint16_t GetCharacterFromXEvent(const XEvent* xev) {
}
DomKey GetDomKeyFromXEvent(const XEvent* xev) {
XEvent xkeyevent = {0};
XEvent xkeyevent;
xkeyevent.xkey = {};
XKeyEvent xkey;
if (xev->type == GenericEvent) {
// Convert the XI2 key event into a core key event so that we can
......
......@@ -79,7 +79,8 @@ std::unique_ptr<ui::Event> TranslateXI2EventToEvent(const XEvent& xev) {
switch (event_type) {
case ET_KEY_PRESSED:
case ET_KEY_RELEASED: {
XEvent xkeyevent = {0};
XEvent xkeyevent;
xkeyevent.xkey = {};
InitXKeyEventFromXIDeviceEvent(xev, &xkeyevent);
return CreateKeyEvent(xkeyevent);
}
......
......@@ -92,7 +92,8 @@ class UIControlsDesktopX11 : public UIControlsAura {
aura::WindowTreeHost* host = window->GetHost();
XEvent xevent = {0};
XEvent xevent;
xevent.xkey = {};
xevent.xkey.type = KeyPress;
if (control) {
SetKeycodeAndSendThenMask(host, &xevent, XK_Control_L, ControlMask);
......@@ -152,7 +153,8 @@ class UIControlsDesktopX11 : public UIControlsAura {
// current mouse position as a result of XGrabPointer()
root_window->MoveCursorTo(root_location);
} else {
XEvent xevent = {0};
XEvent xevent;
xevent.xmotion = {};
XMotionEvent* xmotion = &xevent.xmotion;
xmotion->type = MotionNotify;
xmotion->x = root_location.x();
......@@ -175,7 +177,8 @@ class UIControlsDesktopX11 : public UIControlsAura {
int button_state,
base::OnceClosure closure,
int accelerator_state) override {
XEvent xevent = {0};
XEvent xevent;
xevent.xbutton = {};
XButtonEvent* xbutton = &xevent.xbutton;
gfx::Point mouse_loc = aura::Env::GetInstance()->last_mouse_location();
aura::Window* root_window = RootWindowForPoint(mouse_loc);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment