From 0ef41604e88b8a8224818824217ebc09c93789d5 Mon Sep 17 00:00:00 2001 From: Jean-Philippe ANDRE Date: Wed, 25 Mar 2015 15:29:49 -0700 Subject: [PATCH] Ecore: Use calloc() to initialize Ecore_Event_Key fully Some fields (eg. data) may not be properly initialized. Use calloc() instead of malloc() will ensure proper initialization even if we add more fields. These fields (data) would even be passed down to Evas as Evas_Event_Key_Down for instance. --- src/lib/ecore_drm/ecore_drm_evdev.c | 3 +-- src/lib/ecore_psl1ght/ecore_psl1ght.c | 4 ++-- src/lib/ecore_sdl/ecore_sdl.c | 2 +- src/lib/ecore_wayland/ecore_wl_input.c | 2 +- src/lib/ecore_x/xcb/ecore_xcb_events.c | 6 ++---- src/lib/ecore_x/xlib/ecore_x_events.c | 5 ++--- src/modules/ecore_imf/wayland/wayland_imcontext.c | 2 +- 7 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/lib/ecore_drm/ecore_drm_evdev.c b/src/lib/ecore_drm/ecore_drm_evdev.c index a8383fa..cbf58f3 100644 --- a/src/lib/ecore_drm/ecore_drm_evdev.c +++ b/src/lib/ecore_drm/ecore_drm_evdev.c @@ -308,7 +308,7 @@ _device_handle_key(struct libinput_device *device, struct libinput_event_keyboar if (!compose) compose = compose_buffer; - e = malloc(sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) + + e = calloc(1, sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) + ((compose[0] != '\0') ? strlen(compose) : 0) + 3); if (!e) return; @@ -327,7 +327,6 @@ _device_handle_key(struct libinput_device *device, struct libinput_event_keyboar e->timestamp = timestamp; e->same_screen = 1; e->keycode = code; - e->data = NULL; _device_modifiers_update(edev); diff --git a/src/lib/ecore_psl1ght/ecore_psl1ght.c b/src/lib/ecore_psl1ght/ecore_psl1ght.c index ad73f00..e0f5580 100644 --- a/src/lib/ecore_psl1ght/ecore_psl1ght.c +++ b/src/lib/ecore_psl1ght/ecore_psl1ght.c @@ -351,7 +351,7 @@ _ecore_psl1ght_event_key(u16 key) u16 utf16; unsigned int i; - ev = malloc(sizeof(Ecore_Event_Key)); + ev = calloc(1, sizeof(Ecore_Event_Key)); if (!ev) return NULL; ev->timestamp = _ecore_psl1ght_get_time (); @@ -467,7 +467,7 @@ _ecore_psl1ght_pad_button (const char *name, int pressed) { Ecore_Event_Key *ev = NULL; - ev = malloc(sizeof(Ecore_Event_Key)); + ev = calloc(1, sizeof(Ecore_Event_Key)); if (!ev) return; ev->timestamp = _ecore_psl1ght_get_time (); diff --git a/src/lib/ecore_sdl/ecore_sdl.c b/src/lib/ecore_sdl/ecore_sdl.c index 8b58977..ff026f5 100644 --- a/src/lib/ecore_sdl/ecore_sdl.c +++ b/src/lib/ecore_sdl/ecore_sdl.c @@ -129,7 +129,7 @@ _ecore_sdl_event_key(SDL_Event *event, double timestamp) Ecore_Event_Key *ev; unsigned int i; - ev = malloc(sizeof(Ecore_Event_Key)); + ev = calloc(1, sizeof(Ecore_Event_Key)); if (!ev) return NULL; ev->timestamp = timestamp; diff --git a/src/lib/ecore_wayland/ecore_wl_input.c b/src/lib/ecore_wayland/ecore_wl_input.c index d9f2fd3..6a873e0 100644 --- a/src/lib/ecore_wayland/ecore_wl_input.c +++ b/src/lib/ecore_wayland/ecore_wl_input.c @@ -804,7 +804,7 @@ _ecore_wl_input_cb_keyboard_key(void *data, struct wl_keyboard *keyboard EINA_UN _ecore_wl_input_keymap_translate_keysym(sym, input->modifiers, compose, sizeof(compose)); - e = malloc(sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) + + e = calloc(1, sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) + ((compose[0] != '\0') ? strlen(compose) : 0) + 3); if (!e) return; diff --git a/src/lib/ecore_x/xcb/ecore_xcb_events.c b/src/lib/ecore_x/xcb/ecore_xcb_events.c index e37b2aa..0b71451 100644 --- a/src/lib/ecore_x/xcb/ecore_xcb_events.c +++ b/src/lib/ecore_x/xcb/ecore_xcb_events.c @@ -2401,14 +2401,13 @@ _ecore_xcb_event_key_press(xcb_generic_event_t *event) key = _ecore_xcb_keymap_keysym_to_string(sym); if (!key) key = keyname; - e = malloc(sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) + + e = calloc(1, sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) + (compose ? strlen(compose) : 0) + 3); if (e) { e->keyname = (char *)(e + 1); e->key = e->keyname + strlen(keyname) + 1; - e->compose = NULL; if (compose) e->compose = (e->key + strlen(key) + 1); e->string = e->compose; @@ -2471,14 +2470,13 @@ _ecore_xcb_event_key_release(xcb_generic_event_t *event) key = _ecore_xcb_keymap_keysym_to_string(sym); if (!key) key = keyname; - e = malloc(sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) + + e = calloc(1, sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) + (compose ? strlen(compose) : 0) + 3); if (e) { e->keyname = (char *)(e + 1); e->key = e->keyname + strlen(keyname) + 1; - e->compose = NULL; if (compose) e->compose = (e->key + strlen(key) + 1); e->string = e->compose; diff --git a/src/lib/ecore_x/xlib/ecore_x_events.c b/src/lib/ecore_x/xlib/ecore_x_events.c index e14efd7..25d8fa2 100644 --- a/src/lib/ecore_x/xlib/ecore_x_events.c +++ b/src/lib/ecore_x/xlib/ecore_x_events.c @@ -366,9 +366,8 @@ _ecore_key_press(int event, if (!key) key = keyname; - e = - malloc(sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) + - (compose ? strlen(compose) : 0) + 3); + e = calloc(1, sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) + + (compose ? strlen(compose) : 0) + 3); if (!e) goto on_error; diff --git a/src/modules/ecore_imf/wayland/wayland_imcontext.c b/src/modules/ecore_imf/wayland/wayland_imcontext.c index c324d1a..4f2d982 100644 --- a/src/modules/ecore_imf/wayland/wayland_imcontext.c +++ b/src/modules/ecore_imf/wayland/wayland_imcontext.c @@ -466,7 +466,7 @@ text_input_keysym(void *data, "key event (key: %s)", keyname); - e = malloc(sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) + + e = calloc(1, sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) + strlen(string) + 3); if (!e) return; -- 2.7.4