[dev] [vis] [PATCH] Fix handling of file load errors

From: Willem van de Krol <willem.vandekrol_AT_gmail.com>
Date: Tue, 14 Apr 2015 17:25:15 +0200

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
_AT_@ -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
Received on Tue Apr 14 2015 - 17:25:15 CEST

This archive was generated by hypermail 2.3.0 : Tue Apr 14 2015 - 17:36:10 CEST