elm_code_line: fix potential crash.
authorAlastair Poole <netstar@gmail.com>
Thu, 16 Aug 2018 14:12:35 +0000 (10:12 -0400)
committerWoochanlee <wc0917.lee@samsung.com>
Thu, 23 Aug 2018 06:41:00 +0000 (15:41 +0900)
Summary:
This can occur and thus malloc will return NULL when line->length is
0. Check for !line->length and return. Very difficult to reproduce, but
I had managed three times, and avoided a crash.

Reviewers: #committers, ajwillia.ms, zmike

Reviewed By: #committers, zmike

Subscribers: cedric, #reviewers, zmike

Tags: #efl

Differential Revision: https://phab.enlightenment.org/D6842

src/lib/elementary/elm_code_text.c

index 1ebdb09..641dc41 100644 (file)
@@ -189,7 +189,7 @@ elm_code_line_text_remove(Elm_Code_Line *line, unsigned int position, int length
    Elm_Code_File *file;
    char *removed;
 
-   if (!line)
+   if (!line || !line->length)
      return;
 
    removed = malloc(sizeof(char) * line->length - length);