Browse Source

Fix segmentation while file line counting

git-svn-id: https://klish.googlecode.com/svn/trunk@521 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 12 years ago
parent
commit
44720d6395
2 changed files with 6 additions and 3 deletions
  1. 2 1
      clish/shell/shell_spawn.c
  2. 4 2
      clish/shell/shell_tinyrl.c

+ 2 - 1
clish/shell/shell_spawn.c

@@ -123,7 +123,8 @@ static int _loop(clish_shell_t * this, bool_t is_thread)
 			case SHELL_STATE_SYNTAX_ERROR:
 				/* Interactive session doesn't exit on error */
 				if (tinyrl__get_isatty(this->tinyrl) ||
-					!this->current_file->stop_on_error)
+					(this->current_file &&
+					!this->current_file->stop_on_error))
 					running = 0;
 				retval = this->state;
 			default:

+ 4 - 2
clish/shell/shell_tinyrl.c

@@ -214,7 +214,8 @@ static bool_t clish_shell_tinyrl_key_enter(tinyrl_t *this, int key)
 	char *errmsg = NULL;
 
 	/* Inc line counter */
-	context->shell->current_file->line++;
+	if (context->shell->current_file)
+		context->shell->current_file->line++;
 
 	/* Renew prompt */
 	clish_shell_renew_prompt(this);
@@ -287,7 +288,8 @@ static bool_t clish_shell_tinyrl_key_enter(tinyrl_t *this, int key)
 	}
 	/* If error then print message */
 	if (errmsg) {
-		if (tinyrl__get_isatty(this)) {
+		if (tinyrl__get_isatty(this) ||
+			!context->shell->current_file) {
 			fprintf(stderr, "Syntax error: %s\n", errmsg);
 			tinyrl_reset_line_state(this);
 		} else {