From f290f9ca4cb0d1cc6da5ac1d88b14bc99a88f630 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Thu, 1 Sep 2016 21:41:57 +0100 Subject: [PATCH] Elm: Fix crashes with copy/paste of large code Various fixes to the memory management of multiline strings --- src/lib/elementary/elm_code_widget_selection.c | 7 ++++++- src/lib/elementary/elm_code_widget_text.c | 12 +++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/lib/elementary/elm_code_widget_selection.c b/src/lib/elementary/elm_code_widget_selection.c index 7e16a2f..b885688 100644 --- a/src/lib/elementary/elm_code_widget_selection.c +++ b/src/lib/elementary/elm_code_widget_selection.c @@ -233,19 +233,24 @@ EAPI void elm_code_widget_selection_delete(Evas_Object *widget) { Elm_Code_Widget_Data *pd; + Elm_Code_Widget_Selection_Data *selection; pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); if (!pd->selection) return; - if (pd->selection->start_line == pd->selection->end_line) + selection = elm_code_widget_selection_normalized_get(widget); + if (selection->start_line == selection->end_line) _elm_code_widget_selection_delete_single(widget, pd); else _elm_code_widget_selection_delete_multi(widget, pd); + elm_code_widget_cursor_position_set(widget, selection->start_col, selection->start_line); free(pd->selection); pd->selection = NULL; + free(selection); + efl_event_callback_legacy_call(widget, ELM_OBJ_CODE_WIDGET_EVENT_SELECTION_CLEARED, widget); } diff --git a/src/lib/elementary/elm_code_widget_text.c b/src/lib/elementary/elm_code_widget_text.c index bbcbdc3..974ff52 100644 --- a/src/lib/elementary/elm_code_widget_text.c +++ b/src/lib/elementary/elm_code_widget_text.c @@ -50,7 +50,7 @@ _elm_code_widget_text_multi_get(Elm_Code_Widget *widget, Elm_Code_Widget_Data *p line = elm_code_file_line_get(pd->code->file, start_line); start = elm_code_widget_line_text_position_for_column_get(widget, line, start_col); - first = elm_code_line_text_substr(line, start, line->length - start + 1); + first = elm_code_line_text_substr(line, start, line->length - start); line = elm_code_file_line_get(pd->code->file, end_line); end = elm_code_widget_line_text_position_for_column_get(widget, line, end_col + 1); @@ -58,7 +58,7 @@ _elm_code_widget_text_multi_get(Elm_Code_Widget *widget, Elm_Code_Widget_Data *p ret_len = strlen(first) + strlen(last) + newline_len; - for (row = pd->selection->start_line + 1; row < end_line; row++) + for (row = start_line + 1; row < end_line; row++) { line = elm_code_file_line_get(pd->code->file, row); ret_len += line->length + newline_len; @@ -74,10 +74,8 @@ _elm_code_widget_text_multi_get(Elm_Code_Widget *widget, Elm_Code_Widget_Data *p for (row = start_line + 1; row < end_line; row++) { line = elm_code_file_line_get(pd->code->file, row); - if (line->modified) - snprintf(ptr, line->length + 1, "%s", line->modified); - else - snprintf(ptr, line->length + 1, "%s", line->content); + snprintf(ptr, line->length + 1, "%s", + elm_code_line_text_get(line, NULL)); snprintf(ptr + line->length, newline_len + 1, "%s", newline); ptr += line->length + newline_len; @@ -165,7 +163,7 @@ _elm_code_widget_line_text_position_for_column_get(Eo *obj, Elm_Code_Widget_Data int index = 0; const char *chars; - if (line->length == 0 || column == 1) + if (!line || line->length == 0 || column == 1) return 0; if (line->modified) -- 2.7.4