elm_entry: make file loading succeed on 0-sized files
authorMike Blumenkrantz <zmike@samsung.com>
Wed, 16 Jan 2019 16:24:36 +0000 (11:24 -0500)
committerJunsuChoi <jsuya.choi@samsung.com>
Thu, 24 Jan 2019 05:20:18 +0000 (14:20 +0900)
a file which has no data is still a valid file and should be correctly
opened

fix T6562
@fix

Reviewed-by: Cedric BAIL <cedric.bail@free.fr>
Differential Revision: https://phab.enlightenment.org/D7647

src/lib/elementary/elm_entry.c

index 6ab0754..86d6429 100644 (file)
@@ -226,18 +226,24 @@ _file_load(const char *file)
    Eina_File *f;
    char *text = NULL;
    void *tmp = NULL;
+   size_t size;
 
    f = eina_file_open(file, EINA_FALSE);
    if (!f) return NULL;
 
-   tmp = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
-   if (!tmp) goto on_error;
+   size = eina_file_size_get(f);
+   if (size)
+     {
+        tmp = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
+        if (!tmp) goto on_error;
+     }
 
-   text = malloc(eina_file_size_get(f) + 1);
+   text = malloc(size + 1);
    if (!text) goto on_error;
 
-   memcpy(text, tmp, eina_file_size_get(f));
-   text[eina_file_size_get(f)] = 0;
+   if (size)
+     memcpy(text, tmp, size);
+   text[size] = 0;
 
    if (eina_file_map_faulted(f, tmp))
      {