ajwillia-ms pushed a commit to branch master.

http://git.enlightenment.org/tools/edi.git/commit/?id=9c9b92cadac709596f8afc735ba0980213e3675a

commit 9c9b92cadac709596f8afc735ba0980213e3675a
Author: Andy Williams <a...@andywilliams.me>
Date:   Sun Feb 21 18:03:29 2016 +0000

    [editor] Fix crash when deleting selections
    
    If the selection ended in the carriage return the
    editor could craash.
    
    @fix
---
 ChangeLog                                           |  4 ++++
 NEWS                                                |  1 +
 elm_code/src/lib/widget/elm_code_widget_selection.c | 19 ++++++++++++++-----
 3 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 5314b1d..d8a2285 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2016-02-21 ajwillia.ms (Andy Williams)
+
+       * Fix crash when deleting a selection ending in newline
+
 2016-02-11 ajwillia.ms (Andy Williams)
 
        * Add a filename filter to the filepanel
diff --git a/NEWS b/NEWS
index 935a2de..9a9682a 100644
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,7 @@ Bug fixes:
 
   * Focus input popups when they appear
   * Support fish and other non-bash shells for build & test
+  * Fix crash when deleting a selection ending with newline
 
 
 =======
diff --git a/elm_code/src/lib/widget/elm_code_widget_selection.c 
b/elm_code/src/lib/widget/elm_code_widget_selection.c
index 6479123..04df223 100644
--- a/elm_code/src/lib/widget/elm_code_widget_selection.c
+++ b/elm_code/src/lib/widget/elm_code_widget_selection.c
@@ -193,11 +193,20 @@ _elm_code_widget_selection_delete_multi(Elm_Code_Widget 
*widget, Elm_Code_Widget
    last = elm_code_line_text_get(line, &last_length);
    end = elm_code_widget_line_text_position_for_column_get(widget, line, 
selection->end_col);
 
-   length = start + last_length - (end + 1);
-   content = malloc(sizeof(char) * length);
-   strncpy(content, first, start);
-   strncpy(content + start, last + end + 1,
-           last_length - (end + 1));
+   if (last_length == end)
+     {
+        length = start + last_length - end;
+        content = malloc(sizeof(char) * length);
+        strncpy(content, first, start);
+     }
+   else
+     {
+        length = start + last_length - (end + 1);
+        content = malloc(sizeof(char) * length);
+        strncpy(content, first, start);
+
+        strncpy(content + start, last + end + 1, last_length - (end + 1));
+     }
 
    for (i = line->number; i > selection->start_line; i--)
      elm_code_file_line_remove(pd->code->file, i);

-- 


Reply via email to