forked from enlightenment/edi
editor: fix nulls being appended to lines
Should resolve issues with nulls being inserted and also crashes on pasting into a selection
This commit is contained in:
parent
1845bd517e
commit
5cbab1fa72
|
@ -32,7 +32,7 @@ elm_code_line_text_set(Elm_Code_Line *line, const char *chars, unsigned int leng
|
|||
if (line->modified)
|
||||
free(line->modified);
|
||||
|
||||
newtext = malloc(sizeof(char) * length + 1);
|
||||
newtext = malloc(sizeof(char) * length);
|
||||
strncpy(newtext, chars, length);
|
||||
line->modified = newtext;
|
||||
line->length = length;
|
||||
|
@ -144,7 +144,7 @@ elm_code_line_text_insert(Elm_Code_Line *line, unsigned int position, const char
|
|||
if (!line)
|
||||
return;
|
||||
|
||||
inserted = malloc(sizeof(char) * line->length + length + 1);
|
||||
inserted = malloc(sizeof(char) * line->length + length);
|
||||
if (position > 0)
|
||||
position--;
|
||||
if (position > line->length)
|
||||
|
@ -183,7 +183,7 @@ elm_code_line_text_remove(Elm_Code_Line *line, unsigned int position, int length
|
|||
if (!line)
|
||||
return;
|
||||
|
||||
removed = malloc(sizeof(char) * line->length - length + 1);
|
||||
removed = malloc(sizeof(char) * line->length - length);
|
||||
if (position > 0)
|
||||
position--;
|
||||
if (position > line->length)
|
||||
|
|
|
@ -117,8 +117,9 @@ _elm_code_widget_selection_delete_single(Elm_Code_Widget_Data *pd)
|
|||
|
||||
line = elm_code_file_line_get(pd->code->file, pd->selection->start_line);
|
||||
old = elm_code_line_text_get(line, &old_length);
|
||||
length = line->length - (pd->selection->end_col - pd->selection->start_col);
|
||||
content = malloc(sizeof(char) * (length + 1));
|
||||
length = line->length - (pd->selection->end_col - pd->selection->start_col + 1);
|
||||
content = malloc(sizeof(char) * length);
|
||||
|
||||
snprintf(content, pd->selection->start_col, old);
|
||||
snprintf(content + pd->selection->start_col - 1, old_length - pd->selection->end_col + 1,
|
||||
old + pd->selection->end_col);
|
||||
|
|
Loading…
Reference in New Issue