From bb091424776cfd1fed5ba9e4dbfb479d66474fbe Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Wed, 16 Jan 2019 11:24:36 -0500 Subject: [PATCH] elm_entry: make file loading succeed on 0-sized files a file which has no data is still a valid file and should be correctly opened fix T6562 @fix Reviewed-by: Cedric BAIL Differential Revision: https://phab.enlightenment.org/D7647 --- src/lib/elementary/elm_entry.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/lib/elementary/elm_entry.c b/src/lib/elementary/elm_entry.c index dac8e916f6..8661778d09 100644 --- a/src/lib/elementary/elm_entry.c +++ b/src/lib/elementary/elm_entry.c @@ -143,18 +143,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)) {