Permission errors are handled in text_load(). To detect these errors,
and other open() errors (opening a directory, for example), check the
return value of text_load().

This fixes a segmentation fault when opening a directory.
Also, opening a file you are not permitted to read, will now give an
error, instead of showing the file as empty.

---
 editor.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/editor.c b/editor.c
index 7b0c7b2..20ceb38 100644
--- a/editor.c
+++ b/editor.c
@@ -298,7 +298,9 @@ static VisText *vis_text_new(Editor *ed, const
char *filename) {
                }
        }

-       Text *data = text_load(filename && access(filename, F_OK) == 0 ?
filename : NULL);
+       Text *data = text_load(filename);
+       if (!data)
+               return NULL;
        if (filename)
                text_filename_set(data, filename);
        
-- 
2.3.5

Reply via email to