Elm: Fix crashes with copy/paste of large code

Various fixes to the memory management of multiline strings
This commit is contained in:
Andy Williams 2016-09-01 21:41:57 +01:00
parent b52725cef5
commit f290f9ca4c
2 changed files with 11 additions and 8 deletions

View File

@ -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);
}

View File

@ -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)