summaryrefslogtreecommitdiff
path: root/src/lib/elementary/efl_ui_table_layout.c
diff options
context:
space:
mode:
authorMike Blumenkrantz <zmike@samsung.com>2019-07-17 13:08:58 -0400
committerCedric BAIL <cedric.bail@free.fr>2019-07-19 10:54:59 -0700
commit8e3877cc230b9d24e50982c3997c5f4df7eb45c3 (patch)
tree0cc27a71ef33751391d749253fec9978455ecc14 /src/lib/elementary/efl_ui_table_layout.c
parenta0952b0c01594e34f74a959d5dc4e8d54ab847c9 (diff)
efl_ui/table: avoid exploding stack with lots of subobjects
using alloca like this without any limits is dangerous, so switch to malloc here in such cases Reviewed-by: Marcel Hollerbach <mail@marcel-hollerbach.de> Differential Revision: https://phab.enlightenment.org/D9344
Diffstat (limited to 'src/lib/elementary/efl_ui_table_layout.c')
-rw-r--r--src/lib/elementary/efl_ui_table_layout.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/lib/elementary/efl_ui_table_layout.c b/src/lib/elementary/efl_ui_table_layout.c
index 3918780..013a35a 100644
--- a/src/lib/elementary/efl_ui_table_layout.c
+++ b/src/lib/elementary/efl_ui_table_layout.c
@@ -228,6 +228,7 @@ _efl_ui_table_custom_layout(Efl_Ui_Table *ui_table, Efl_Ui_Table_Data *pd)
228 int (*_efl_ui_table_item_pos_get[2])(Table_Calc *, Item_Calc *, Eina_Bool); 228 int (*_efl_ui_table_item_pos_get[2])(Table_Calc *, Item_Calc *, Eina_Bool);
229 int (*_efl_ui_table_item_size_get[2])(Table_Calc *, Item_Calc *, Eina_Bool); 229 int (*_efl_ui_table_item_size_get[2])(Table_Calc *, Item_Calc *, Eina_Bool);
230 Table_Calc table_calc; 230 Table_Calc table_calc;
231 Eina_Bool do_free;
231 232
232 count = pd->count; 233 count = pd->count;
233 234
@@ -250,7 +251,17 @@ _efl_ui_table_custom_layout(Efl_Ui_Table *ui_table, Efl_Ui_Table_Data *pd)
250 memset(table_calc.cell_calc[0], 0, cols * sizeof(Cell_Calc)); 251 memset(table_calc.cell_calc[0], 0, cols * sizeof(Cell_Calc));
251 memset(table_calc.cell_calc[1], 0, rows * sizeof(Cell_Calc)); 252 memset(table_calc.cell_calc[1], 0, rows * sizeof(Cell_Calc));
252 253
253 items = alloca(count * sizeof(*items)); 254 /* Item_Calc struct is currently 152 bytes.
255 * this is pretty big to be allocating a huge number of, and we don't want to explode the stack
256 */
257 do_free = count >= 500;
258 if (do_free)
259 {
260 items = malloc(count * sizeof(*items));
261 EINA_SAFETY_ON_NULL_RETURN(items);
262 }
263 else
264 items = alloca(count * sizeof(*items));
254#ifdef DEBUG 265#ifdef DEBUG
255 memset(items, 0, count * sizeof(*items)); 266 memset(items, 0, count * sizeof(*items));
256#endif 267#endif
@@ -384,4 +395,5 @@ _efl_ui_table_custom_layout(Efl_Ui_Table *ui_table, Efl_Ui_Table_Data *pd)
384 EINA_SIZE2D(table_calc.want[0], 395 EINA_SIZE2D(table_calc.want[0],
385 table_calc.want[1])); 396 table_calc.want[1]));
386 efl_event_callback_call(ui_table, EFL_PACK_EVENT_LAYOUT_UPDATED, NULL); 397 efl_event_callback_call(ui_table, EFL_PACK_EVENT_LAYOUT_UPDATED, NULL);
398 if (do_free) free(items);
387} 399}