Browse Source

[bim] Bail early trying to edit a directory

K. Lange 5 years ago
parent
commit
991fb36690
1 changed files with 6 additions and 1 deletions
  1. 6 1
      apps/bim.c

+ 6 - 1
apps/bim.c

@@ -2825,11 +2825,16 @@ void open_file(char * file) {
 
 	state = 0;
 
-	while (!feof(f)) {
+	while (!feof(f) && !ferror(f)) {
 		size_t r = fread(buf, 1, BLOCK_SIZE, f);
 		add_buffer(buf, r);
 	}
 
+	if (ferror(f)) {
+		env->loading = 0;
+		return;
+	}
+
 	if (env->line_no && env->lines[env->line_no-1] && env->lines[env->line_no-1]->actual == 0) {
 		/* Remove blank line from end */
 		remove_line(env->lines, env->line_no-1);