From 1ad03a2e49000fbeda0f43306518743e3048e810 Mon Sep 17 00:00:00 2001 From: Daniel Zaoui Date: Thu, 22 Sep 2016 07:52:27 +0300 Subject: [PATCH] Modify macro to prevent simple-but-hard-to-find bugs One of them is to forget to replace the struct name during a line copy, leading to write bad data in the recording file and to its corruption. --- src/lib/tsuite_evas_hook.c | 69 ++++++++++++++------------------------ 1 file changed, 26 insertions(+), 43 deletions(-) diff --git a/src/lib/tsuite_evas_hook.c b/src/lib/tsuite_evas_hook.c index 20eb596..268ec18 100644 --- a/src/lib/tsuite_evas_hook.c +++ b/src/lib/tsuite_evas_hook.c @@ -96,19 +96,19 @@ _is_hook_duplicate(const Variant_st *v, Tsuite_Event_Type ev_type, const void *i } /* Adding variant to list, this list is later written to EET file */ -#define ADD_TO_LIST(EVT_TYPE, EVT_STRUCT_NAME, INFO) \ +#define ADD_TO_LIST(EVT_TYPE, INFO) \ do { /* This macro will add event to EET data list */ \ if (vr_list && _hook_setting->recording) \ { \ const Variant_st *prev_v = eina_list_last_data_get(vr_list->variant_list); \ - if (!prev_v || !_is_hook_duplicate(prev_v, EVT_TYPE, &INFO, sizeof(EVT_STRUCT_NAME))) \ + if (!prev_v || !_is_hook_duplicate(prev_v, EVT_TYPE, &INFO, sizeof(INFO))) \ { \ printf("Recording %s\n", tsuite_event_mapping_type_str_get(EVT_TYPE)); \ Variant_st *v = malloc(sizeof(Variant_st)); \ - v->data = malloc(sizeof(EVT_STRUCT_NAME)); \ + v->data = malloc(sizeof(INFO)); \ _variant_type_set(tsuite_event_mapping_type_str_get(EVT_TYPE), \ &v->t, EINA_FALSE); \ - memcpy(v->data, &INFO, sizeof(EVT_STRUCT_NAME)); \ + memcpy(v->data, &INFO, sizeof(INFO)); \ vr_list->variant_list = eina_list_append(vr_list->variant_list, v); \ } \ } \ @@ -444,7 +444,7 @@ _event_pointer_cb(void *data, const Efl_Event *event) int x = 0, y = 0; efl_input_pointer_position_get(evp, &x, &y); multi_move t = { tool, x, y, rad, radx, rady, pres, ang, fx, fy, timestamp, n_evas }; - if (t.n_evas >= 0) ADD_TO_LIST(evt, multi_move, t); + if (t.n_evas >= 0) ADD_TO_LIST(evt, t); break; } case EFL_POINTER_ACTION_DOWN: case EFL_POINTER_ACTION_UP: @@ -457,13 +457,13 @@ _event_pointer_cb(void *data, const Efl_Event *event) Efl_Pointer_Flags flags = efl_input_pointer_button_flags_get(evp); multi_event t = { tool, b, x, y, rad, radx, rady, pres, ang, fx, fy, flags, timestamp, n_evas }; - if (t.n_evas >= 0) ADD_TO_LIST(evt, multi_event, t); + if (t.n_evas >= 0) ADD_TO_LIST(evt, t); break; } case EFL_POINTER_ACTION_IN: case EFL_POINTER_ACTION_OUT: { mouse_in_mouse_out t = { timestamp, n_evas }; - if (t.n_evas >= 0) ADD_TO_LIST(evt, mouse_in_mouse_out, t); + if (t.n_evas >= 0) ADD_TO_LIST(evt, t); break; } case EFL_POINTER_ACTION_WHEEL: @@ -471,7 +471,7 @@ _event_pointer_cb(void *data, const Efl_Event *event) int direction = efl_input_pointer_wheel_direction_get(evp); int z = efl_input_pointer_wheel_delta_get(evp); mouse_wheel t = { direction, z, timestamp, n_evas }; - if (t.n_evas >= 0) ADD_TO_LIST(evt, mouse_wheel, t); + if (t.n_evas >= 0) ADD_TO_LIST(evt, t); break; } default: @@ -498,8 +498,7 @@ _event_key_cb(void *data, const Efl_Event *event) printf("Take Screenshot: %s timestamp=<%u>\n", __func__, timestamp); #endif take_screenshot t = { timestamp, n_evas }; - if (t.n_evas >= 0) - ADD_TO_LIST(TSUITE_EVENT_TAKE_SHOT, take_screenshot, t); + if (t.n_evas >= 0) ADD_TO_LIST(TSUITE_EVENT_TAKE_SHOT, t); return; } if (!strcmp(key, SAVE_KEY_STR)) @@ -530,7 +529,7 @@ _event_key_cb(void *data, const Efl_Event *event) t.compose = eina_stringshare_add(efl_input_key_compose_get(evk)); t.keycode = efl_input_key_code_get(evk); t.n_evas = n_evas; - if (t.n_evas >= 0) ADD_TO_LIST(evt, key_down_key_up_with_keycode, t); + if (t.n_evas >= 0) ADD_TO_LIST(evt, t); } } @@ -953,8 +952,7 @@ evas_event_feed_mouse_in(Evas *e, unsigned int timestamp, const void *data) #endif mouse_in_mouse_out t = { timestamp, evas_list_find(e) }; int evt = tsuite_event_type_get(EVAS_CALLBACK_MOUSE_IN); - if (t.n_evas >= 0) - ADD_TO_LIST(evt, mouse_in_mouse_out, t); + if (t.n_evas >= 0) ADD_TO_LIST(evt, t); void (*orig) (Evas *e, unsigned int timestamp, const void *data) = dlsym(RTLD_NEXT, __func__); @@ -971,8 +969,7 @@ evas_event_feed_mouse_out(Evas *e, unsigned int timestamp, const void *data) #endif mouse_in_mouse_out t = { timestamp, evas_list_find(e) }; int evt = tsuite_event_type_get(EVAS_CALLBACK_MOUSE_OUT); - if (t.n_evas >= 0) - ADD_TO_LIST(evt, mouse_in_mouse_out, t); + if (t.n_evas >= 0) ADD_TO_LIST(evt, t); void (*orig) (Evas *e, unsigned int timestamp, const void *data) = dlsym(RTLD_NEXT, __func__); @@ -990,8 +987,7 @@ evas_event_feed_mouse_down(Evas *e, int b, Evas_Button_Flags flags, #endif mouse_down_mouse_up t = { b, flags, timestamp, evas_list_find(e) }; int evt = tsuite_event_type_get(EVAS_CALLBACK_MOUSE_DOWN); - if (t.n_evas >= 0) - ADD_TO_LIST(evt, mouse_down_mouse_up, t); + if (t.n_evas >= 0) ADD_TO_LIST(evt, t); void (*orig) (Evas *e, int b, Evas_Button_Flags flags, unsigned int timestamp, const void *data) = @@ -1010,8 +1006,7 @@ evas_event_feed_mouse_up(Evas *e, int b, Evas_Button_Flags flags, #endif mouse_down_mouse_up t = { b, flags, timestamp, evas_list_find(e) }; int evt = tsuite_event_type_get(EVAS_CALLBACK_MOUSE_UP); - if (t.n_evas >= 0) - ADD_TO_LIST(evt, mouse_down_mouse_up, t); + if (t.n_evas >= 0) ADD_TO_LIST(evt, t); void (*orig) (Evas *e, int b, Evas_Button_Flags flags, unsigned int timestamp, const void *data) = @@ -1030,8 +1025,7 @@ evas_event_feed_mouse_move(Evas *e, int x, int y, unsigned int timestamp, printf("Calling %s timestamp=<%u>\n", __func__, timestamp); #endif int evt = tsuite_event_type_get(EVAS_CALLBACK_MOUSE_MOVE); - if (t.n_evas >= 0) - ADD_TO_LIST(evt, mouse_move, t); + if (t.n_evas >= 0) ADD_TO_LIST(evt, t); void (*orig) (Evas *e, int x, int y, unsigned int timestamp, const void *data) = dlsym(RTLD_NEXT, __func__); @@ -1049,8 +1043,7 @@ evas_event_input_mouse_move(Evas *e, int x, int y, unsigned int timestamp, printf("Calling %s timestamp=<%u>\n", __func__, timestamp); #endif int evt = tsuite_event_type_get(EVAS_CALLBACK_MOUSE_MOVE); - if (t.n_evas >= 0) - ADD_TO_LIST(evt, mouse_move, t); + if (t.n_evas >= 0) ADD_TO_LIST(evt, t); void (*orig) (Evas *e, int x, int y, unsigned int timestamp, const void *data) = dlsym(RTLD_NEXT, __func__); @@ -1067,8 +1060,7 @@ evas_event_feed_mouse_wheel(Evas *e, int direction, int z, #endif mouse_wheel t = { direction, z, timestamp, evas_list_find(e) }; int evt = tsuite_event_type_get(EVAS_CALLBACK_MOUSE_WHEEL); - if (t.n_evas >= 0) - ADD_TO_LIST(evt, mouse_wheel, t); + if (t.n_evas >= 0) ADD_TO_LIST(evt, t); void (*orig) (Evas *e, int direction, int z, unsigned int timestamp, const void *data) = dlsym(RTLD_NEXT, __func__); @@ -1090,8 +1082,7 @@ evas_event_feed_multi_down(Evas *e, int d, int x, int y, fx, fy, flags, timestamp, evas_list_find(e)}; int evt = tsuite_event_type_get(EVAS_CALLBACK_MULTI_DOWN); - if (t.n_evas >= 0) - ADD_TO_LIST(evt, multi_event, t); + if (t.n_evas >= 0) ADD_TO_LIST(evt, t); void (*orig) (Evas *e, int d, int x, int y, double rad, double radx, double rady, double pres, double ang, @@ -1113,8 +1104,7 @@ evas_event_feed_multi_up(Evas *e, int d, int x, int y, #endif multi_event t = { d, 0, x, y, rad, radx, rady, pres, ang, fx, fy, flags, timestamp, evas_list_find(e) }; int evt = tsuite_event_type_get(EVAS_CALLBACK_MULTI_UP); - if (t.n_evas >= 0) - ADD_TO_LIST(evt, multi_event, t); + if (t.n_evas >= 0) ADD_TO_LIST(evt, t); void (*orig) (Evas *e, int d, int x, int y, double rad, double radx, double rady, double pres, double ang, @@ -1136,8 +1126,7 @@ evas_event_feed_multi_move(Evas *e, int d, int x, int y, double rad, #endif multi_move t = { d, x, y, rad, radx, rady, pres, ang, fx, fy, timestamp, evas_list_find(e) }; int evt = tsuite_event_type_get(EVAS_CALLBACK_MULTI_MOVE); - if (t.n_evas >= 0) - ADD_TO_LIST(evt, multi_move, t); + if (t.n_evas >= 0) ADD_TO_LIST(evt, t); void (*orig) (Evas *e, int d, int x, int y, double rad, double radx, double rady, double pres, double ang, @@ -1167,8 +1156,7 @@ evas_event_feed_key_down(Evas *e, const char *keyname, const char *key, printf("Take Screenshot: %s timestamp=<%u>\n", __func__, timestamp); #endif take_screenshot t = { timestamp, evas_list_find(e) }; - if (t.n_evas >= 0) - ADD_TO_LIST(TSUITE_EVENT_TAKE_SHOT, take_screenshot, t); + if (t.n_evas >= 0) ADD_TO_LIST(TSUITE_EVENT_TAKE_SHOT, t); orig(e, keyname, key, string, compose, timestamp, data); return; @@ -1196,8 +1184,7 @@ evas_event_feed_key_down(Evas *e, const char *keyname, const char *key, t.string = eina_stringshare_add(string); t.compose = eina_stringshare_add(compose); t.n_evas = evas_list_find(e); - if (t.n_evas >= 0) - ADD_TO_LIST(evt, key_down_key_up, t); + if (t.n_evas >= 0) ADD_TO_LIST(evt, t); } orig(e, keyname, key, string, compose, timestamp, data); @@ -1246,8 +1233,7 @@ evas_event_feed_key_up(Evas *e, const char *keyname, const char *key, t.string = eina_stringshare_add(string); t.compose = eina_stringshare_add(compose); t.n_evas = evas_list_find(e); - if (t.n_evas >= 0) - ADD_TO_LIST(evt, key_down_key_up, t); + if (t.n_evas >= 0) ADD_TO_LIST(evt, t); } orig(e, keyname, key, string, compose, timestamp, data); @@ -1273,8 +1259,7 @@ evas_event_feed_key_down_with_keycode(Evas *e, const char *keyname, const char * printf("Take Screenshot: %s timestamp=<%u>\n", __func__, timestamp); #endif take_screenshot t = { timestamp, evas_list_find(e) }; - if (t.n_evas >= 0) - ADD_TO_LIST(TSUITE_EVENT_TAKE_SHOT, take_screenshot, t); + if (t.n_evas >= 0) ADD_TO_LIST(TSUITE_EVENT_TAKE_SHOT, t); orig(e, keyname, key, string, compose, timestamp, data, keycode); return; @@ -1303,8 +1288,7 @@ evas_event_feed_key_down_with_keycode(Evas *e, const char *keyname, const char * t.compose = eina_stringshare_add(compose); t.n_evas = evas_list_find(e); t.keycode = keycode; - if (t.n_evas >= 0) - ADD_TO_LIST(evt, key_down_key_up, t); + if (t.n_evas >= 0) ADD_TO_LIST(evt, t); } orig(e, keyname, key, string, compose, timestamp, data, keycode); @@ -1354,8 +1338,7 @@ evas_event_feed_key_up_with_keycode(Evas *e, const char *keyname, const char *ke t.compose = eina_stringshare_add(compose); t.n_evas = evas_list_find(e); t.keycode = keycode; - if (t.n_evas >= 0) - ADD_TO_LIST(evt, key_down_key_up, t); + if (t.n_evas >= 0) ADD_TO_LIST(evt, t); } orig(e, keyname, key, string, compose, timestamp, data, keycode);