summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2016-08-18 17:06:17 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2016-08-26 10:18:01 +0900
commitab7f281c3461313d907ef8cac238cb380cd3da6d (patch)
tree5456e180755734c69c38ef6a400f941ea148cf37
parentac26c7d4f382a968c505cfa317baf76c38f613a0 (diff)
evas events: Fix crash when translating legacy events
An obvious crash happened when reusing a legacy struct from another type.
-rw-r--r--src/lib/evas/canvas/evas_events_legacy.c52
1 files changed, 40 insertions, 12 deletions
diff --git a/src/lib/evas/canvas/evas_events_legacy.c b/src/lib/evas/canvas/evas_events_legacy.c
index a42ae643fb..2dcdb6896e 100644
--- a/src/lib/evas/canvas/evas_events_legacy.c
+++ b/src/lib/evas/canvas/evas_events_legacy.c
@@ -4,6 +4,34 @@
4#define EFL_INTERNAL_UNSTABLE 4#define EFL_INTERNAL_UNSTABLE
5#include "interfaces/efl_common_internal.h" 5#include "interfaces/efl_common_internal.h"
6 6
7typedef union {
8 Evas_Event_Mouse_Down down;
9 Evas_Event_Mouse_Up up;
10 Evas_Event_Mouse_In in;
11 Evas_Event_Mouse_Out out;
12 Evas_Event_Mouse_Move move;
13 Evas_Event_Mouse_Wheel wheel;
14 Evas_Event_Multi_Down mdown;
15 Evas_Event_Multi_Up mup;
16 Evas_Event_Multi_Move mmove;
17 Evas_Event_Key_Down kdown;
18 Evas_Event_Key_Up kup;
19 Evas_Event_Hold hold;
20 Evas_Event_Axis_Update axis;
21} Evas_Event_Any;
22
23#define EV_SIZE sizeof(Evas_Event_Any)
24
25static inline void *
26_event_alloc(void *old)
27{
28 if (old)
29 memset(old, 0, EV_SIZE);
30 else
31 old = calloc(1, EV_SIZE);
32 return old;
33}
34
7Eina_Bool 35Eina_Bool
8efl_event_pointer_legacy_info_set(Efl_Event_Pointer *evt, const void *event_info, Evas_Callback_Type type) 36efl_event_pointer_legacy_info_set(Efl_Event_Pointer *evt, const void *event_info, Evas_Callback_Type type)
9{ 37{
@@ -223,7 +251,7 @@ efl_event_pointer_legacy_info_fill(Efl_Event_Key *evt, Evas_Callback_Type type,
223 case EFL_POINTER_ACTION_IN: 251 case EFL_POINTER_ACTION_IN:
224 TYPE_CHK(MOUSE_IN); 252 TYPE_CHK(MOUSE_IN);
225 { 253 {
226 Evas_Event_Mouse_In *e = ev->legacy ? ev->legacy : calloc(1, sizeof(*e)); 254 Evas_Event_Mouse_In *e = _event_alloc(ev->legacy);
227 e->canvas.x = ev->cur.x; 255 e->canvas.x = ev->cur.x;
228 e->canvas.y = ev->cur.y; 256 e->canvas.y = ev->cur.y;
229 COORD_DUP(e); 257 COORD_DUP(e);
@@ -242,7 +270,7 @@ efl_event_pointer_legacy_info_fill(Efl_Event_Key *evt, Evas_Callback_Type type,
242 case EFL_POINTER_ACTION_OUT: 270 case EFL_POINTER_ACTION_OUT:
243 TYPE_CHK(MOUSE_OUT); 271 TYPE_CHK(MOUSE_OUT);
244 { 272 {
245 Evas_Event_Mouse_Out *e = ev->legacy ? ev->legacy : calloc(1, sizeof(*e)); 273 Evas_Event_Mouse_Out *e = _event_alloc(ev->legacy);
246 e->canvas.x = ev->cur.x; 274 e->canvas.x = ev->cur.x;
247 e->canvas.y = ev->cur.y; 275 e->canvas.y = ev->cur.y;
248 COORD_DUP(e); 276 COORD_DUP(e);
@@ -262,7 +290,7 @@ efl_event_pointer_legacy_info_fill(Efl_Event_Key *evt, Evas_Callback_Type type,
262 if (ev->finger == 0) 290 if (ev->finger == 0)
263 { 291 {
264 TYPE_CHK(MOUSE_DOWN); 292 TYPE_CHK(MOUSE_DOWN);
265 Evas_Event_Mouse_Down *e = ev->legacy ? ev->legacy : calloc(1, sizeof(*e)); 293 Evas_Event_Mouse_Down *e = _event_alloc(ev->legacy);
266 e->button = ev->button; 294 e->button = ev->button;
267 e->canvas.x = ev->cur.x; 295 e->canvas.x = ev->cur.x;
268 e->canvas.y = ev->cur.y; 296 e->canvas.y = ev->cur.y;
@@ -282,7 +310,7 @@ efl_event_pointer_legacy_info_fill(Efl_Event_Key *evt, Evas_Callback_Type type,
282 else 310 else
283 { 311 {
284 TYPE_CHK(MULTI_DOWN); 312 TYPE_CHK(MULTI_DOWN);
285 Evas_Event_Multi_Down *e = ev->legacy ? ev->legacy : calloc(1, sizeof(*e)); 313 Evas_Event_Multi_Down *e = _event_alloc(ev->legacy);
286 e->device = ev->finger; 314 e->device = ev->finger;
287 e->radius = ev->radius; 315 e->radius = ev->radius;
288 e->radius_x = ev->radius_x; 316 e->radius_x = ev->radius_x;
@@ -310,7 +338,7 @@ efl_event_pointer_legacy_info_fill(Efl_Event_Key *evt, Evas_Callback_Type type,
310 if (ev->finger == 0) 338 if (ev->finger == 0)
311 { 339 {
312 TYPE_CHK(MOUSE_UP); 340 TYPE_CHK(MOUSE_UP);
313 Evas_Event_Mouse_Up *e = ev->legacy ? ev->legacy : calloc(1, sizeof(*e)); 341 Evas_Event_Mouse_Up *e = _event_alloc(ev->legacy);
314 e->button = ev->button; 342 e->button = ev->button;
315 e->canvas.x = ev->cur.x; 343 e->canvas.x = ev->cur.x;
316 e->canvas.y = ev->cur.y; 344 e->canvas.y = ev->cur.y;
@@ -330,7 +358,7 @@ efl_event_pointer_legacy_info_fill(Efl_Event_Key *evt, Evas_Callback_Type type,
330 else 358 else
331 { 359 {
332 TYPE_CHK(MULTI_UP); 360 TYPE_CHK(MULTI_UP);
333 Evas_Event_Multi_Up *e = ev->legacy ? ev->legacy : calloc(1, sizeof(*e)); 361 Evas_Event_Multi_Up *e = _event_alloc(ev->legacy);
334 e->device = ev->finger; 362 e->device = ev->finger;
335 e->radius = ev->radius; 363 e->radius = ev->radius;
336 e->radius_x = ev->radius_x; 364 e->radius_x = ev->radius_x;
@@ -358,7 +386,7 @@ efl_event_pointer_legacy_info_fill(Efl_Event_Key *evt, Evas_Callback_Type type,
358 if (ev->finger == 0) 386 if (ev->finger == 0)
359 { 387 {
360 TYPE_CHK(MOUSE_MOVE); 388 TYPE_CHK(MOUSE_MOVE);
361 Evas_Event_Mouse_Move *e = ev->legacy ? ev->legacy : calloc(1, sizeof(*e)); 389 Evas_Event_Mouse_Move *e = _event_alloc(ev->legacy);
362 e->buttons = ev->pressed_buttons; 390 e->buttons = ev->pressed_buttons;
363 e->cur.canvas.x = ev->cur.x; 391 e->cur.canvas.x = ev->cur.x;
364 e->cur.canvas.y = ev->cur.y; 392 e->cur.canvas.y = ev->cur.y;
@@ -380,7 +408,7 @@ efl_event_pointer_legacy_info_fill(Efl_Event_Key *evt, Evas_Callback_Type type,
380 else 408 else
381 { 409 {
382 TYPE_CHK(MULTI_MOVE); 410 TYPE_CHK(MULTI_MOVE);
383 Evas_Event_Multi_Move *e = ev->legacy ? ev->legacy : calloc(1, sizeof(*e)); 411 Evas_Event_Multi_Move *e = _event_alloc(ev->legacy);
384 e->device = ev->finger; 412 e->device = ev->finger;
385 e->radius = ev->radius; 413 e->radius = ev->radius;
386 e->radius_x = ev->radius_x; 414 e->radius_x = ev->radius_x;
@@ -406,7 +434,7 @@ efl_event_pointer_legacy_info_fill(Efl_Event_Key *evt, Evas_Callback_Type type,
406 case EFL_POINTER_ACTION_WHEEL: 434 case EFL_POINTER_ACTION_WHEEL:
407 { 435 {
408 TYPE_CHK(MOUSE_WHEEL); 436 TYPE_CHK(MOUSE_WHEEL);
409 Evas_Event_Mouse_Wheel *e = ev->legacy ? ev->legacy : calloc(1, sizeof(*e)); 437 Evas_Event_Mouse_Wheel *e = _event_alloc(ev->legacy);
410 e->direction = (ev->wheel.dir == EFL_ORIENT_HORIZONTAL) ? 1 : 0; 438 e->direction = (ev->wheel.dir == EFL_ORIENT_HORIZONTAL) ? 1 : 0;
411 e->z = ev->wheel.z; 439 e->z = ev->wheel.z;
412 e->canvas.x = ev->cur.x; 440 e->canvas.x = ev->cur.x;
@@ -490,7 +518,7 @@ efl_event_key_legacy_info_fill(Efl_Event_Key *evt, Evas_Event_Flags **pflags)
490 518
491 if (ev->pressed) 519 if (ev->pressed)
492 { 520 {
493 Evas_Event_Key_Down *e = ev->legacy ? ev->legacy : calloc(1, sizeof(*e)); 521 Evas_Event_Key_Down *e = _event_alloc(ev->legacy);
494 e->timestamp = ev->timestamp; 522 e->timestamp = ev->timestamp;
495 e->keyname = (char *) ev->keyname; 523 e->keyname = (char *) ev->keyname;
496 e->key = ev->key; 524 e->key = ev->key;
@@ -508,7 +536,7 @@ efl_event_key_legacy_info_fill(Efl_Event_Key *evt, Evas_Event_Flags **pflags)
508 } 536 }
509 else 537 else
510 { 538 {
511 Evas_Event_Key_Up *e = ev->legacy ? ev->legacy : calloc(1, sizeof(*e)); 539 Evas_Event_Key_Up *e = _event_alloc(ev->legacy);
512 e->timestamp = ev->timestamp; 540 e->timestamp = ev->timestamp;
513 e->keyname = (char *) ev->keyname; 541 e->keyname = (char *) ev->keyname;
514 e->key = ev->key; 542 e->key = ev->key;
@@ -557,7 +585,7 @@ efl_event_hold_legacy_info_fill(Efl_Event_Hold *evt, Evas_Event_Flags **pflags)
557 585
558 if (!ev) return NULL; 586 if (!ev) return NULL;
559 587
560 e = ev->legacy ? ev->legacy : calloc(1, sizeof(*e)); 588 e = _event_alloc(ev->legacy);
561 e->timestamp = ev->timestamp; 589 e->timestamp = ev->timestamp;
562 e->dev = ev->device; 590 e->dev = ev->device;
563 e->hold = ev->hold; 591 e->hold = ev->hold;