Browse Source

Fix segmentation when ostream is NULL.

git-svn-id: https://klish.googlecode.com/svn/trunk@575 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 12 years ago
parent
commit
cf1157222b
3 changed files with 21 additions and 3 deletions
  1. 1 1
      clish/callback_config.c
  2. 1 1
      clish/shell/shell_tinyrl.c
  3. 19 1
      tinyrl/vt100/vt100.c

+ 1 - 1
clish/callback_config.c

@@ -193,7 +193,7 @@ bool_t clish_config_callback(clish_context_t *context)
 					lub_string_free(str);
 					break;
 				}
-				fprintf(clish_shell__get_ostream(this),
+				tinyrl_printf(clish_shell__get_tinyrl(this),
 					"%s\n", str);
 				lub_string_free(str);
 			}

+ 1 - 1
clish/shell/shell_tinyrl.c

@@ -95,7 +95,7 @@ static clish_pargv_status_t clish_shell_tinyrl_expand(tinyrl_t * this)
 		break;
 	case 2:
 		/* just display line */
-		fprintf(tinyrl__get_ostream(this), "\n%s", buffer);
+		tinyrl_printf(this, "\n%s", buffer);
 		free(buffer);
 		buffer = NULL;
 		break;

+ 19 - 1
tinyrl/vt100/vt100.c

@@ -110,6 +110,8 @@ int tinyrl_vt100_printf(const tinyrl_vt100_t * this, const char *fmt, ...)
 	va_list args;
 	int len;
 
+	if (!this->ostream)
+		return 0;
 	va_start(args, fmt);
 	len = tinyrl_vt100_vprintf(this, fmt, args);
 	va_end(args);
@@ -121,6 +123,8 @@ int tinyrl_vt100_printf(const tinyrl_vt100_t * this, const char *fmt, ...)
 int
 tinyrl_vt100_vprintf(const tinyrl_vt100_t * this, const char *fmt, va_list args)
 {
+	if (!this->ostream)
+		return 0;
 	return vfprintf(this->ostream, fmt, args);
 }
 
@@ -174,6 +178,8 @@ int tinyrl_vt100_getchar(const tinyrl_vt100_t *this)
 /*-------------------------------------------------------- */
 int tinyrl_vt100_oflush(const tinyrl_vt100_t * this)
 {
+	if (!this->ostream)
+		return 0;
 	return fflush(this->ostream);
 }
 
@@ -186,6 +192,8 @@ int tinyrl_vt100_ierror(const tinyrl_vt100_t * this)
 /*-------------------------------------------------------- */
 int tinyrl_vt100_oerror(const tinyrl_vt100_t * this)
 {
+	if (!this->ostream)
+		return 0;
 	return ferror(this->ostream);
 }
 
@@ -207,7 +215,12 @@ unsigned int tinyrl_vt100__get_width(const tinyrl_vt100_t *this)
 #ifdef TIOCGWINSZ
 	struct winsize ws;
 	int res;
+#endif
+
+	if(!this->ostream)
+		return 0;
 
+#ifdef TIOCGWINSZ
 	ws.ws_col = 0;
 	res = ioctl(fileno(this->ostream), TIOCGWINSZ, &ws);
 	if (res || !ws.ws_col)
@@ -224,7 +237,12 @@ unsigned int tinyrl_vt100__get_height(const tinyrl_vt100_t *this)
 #ifdef TIOCGWINSZ
 	struct winsize ws;
 	int res;
+#endif
+
+	if(!this->ostream)
+		return 0;
 
+#ifdef TIOCGWINSZ
 	ws.ws_row = 0;
 	res = ioctl(fileno(this->ostream), TIOCGWINSZ, &ws);
 	if (res || !ws.ws_row)
@@ -257,7 +275,7 @@ tinyrl_vt100_t *tinyrl_vt100_new(FILE * istream, FILE * ostream)
 	tinyrl_vt100_t *this = NULL;
 
 	this = malloc(sizeof(tinyrl_vt100_t));
-	if (NULL != this) {
+	if (this) {
 		tinyrl_vt100_init(this, istream, ostream);
 	}