diff mbox series

[06/13] lib: fwts_interactive: add sanity check on fileno, fix typo, tidy code

Message ID 20180814112435.22166-7-colin.king@canonical.com
State Accepted
Headers show
Series lib: minor code clean up | expand

Commit Message

Colin Ian King Aug. 14, 2018, 11:24 a.m. UTC
From: Colin Ian King <colin.king@canonical.com>

However unlikely, we should add a sanity check on the return from
fileno just in case it failed.  Fix a typo in a comment and remove
an empty line.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/src/fwts_interactive.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Alex Hung Aug. 14, 2018, 7:15 p.m. UTC | #1
On 2018-08-14 04:24 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> However unlikely, we should add a sanity check on the return from
> fileno just in case it failed.  Fix a typo in a comment and remove
> an empty line.
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/lib/src/fwts_interactive.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/src/lib/src/fwts_interactive.c b/src/lib/src/fwts_interactive.c
> index 5a8e873e..d1aa70fe 100644
> --- a/src/lib/src/fwts_interactive.c
> +++ b/src/lib/src/fwts_interactive.c
> @@ -33,9 +33,11 @@ static int fwts_getchar(int *ch)
>   {
>   	struct termios oldterm;
>   	struct termios newterm;
> -	int fd = fileno(stdin);
> +	const int fd = fileno(stdin);
>   
>   	*ch = -1;
> +	if (fd < 0)
> +		return FWTS_ERROR;
>   
>   	if (tcgetattr(fd, &oldterm) < 0)
>   		return FWTS_ERROR;
> @@ -76,7 +78,7 @@ int fwts_printf(fwts_framework *fw, const char *fmt, ...)
>   }
>   
>   /*
> - *  fwts_press_entrer()
> + *  fwts_press_enter()
>    *	prompt and wait for enter key
>    */
>   int fwts_press_enter(fwts_framework *fw)
> @@ -111,7 +113,6 @@ int fwts_get_reply(fwts_framework *fw, const char *message, const char *options)
>   	fflush(stdout);
>   
>   	for (;;) {
> -
>   		if (fwts_getchar(&ch) == FWTS_ERROR) {
>   			fwts_log_error(fw, "fwts_getchar() failed.");
>   			break;
> @@ -124,4 +125,3 @@ int fwts_get_reply(fwts_framework *fw, const char *message, const char *options)
>   
>   	return ch;
>   }
> -
> 


Acked-by: Alex Hung <alex.hung@canonical.com>
Ivan Hu Aug. 16, 2018, 9:04 a.m. UTC | #2
On 08/14/2018 07:24 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> However unlikely, we should add a sanity check on the return from
> fileno just in case it failed.  Fix a typo in a comment and remove
> an empty line.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/src/fwts_interactive.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/src/lib/src/fwts_interactive.c b/src/lib/src/fwts_interactive.c
> index 5a8e873e..d1aa70fe 100644
> --- a/src/lib/src/fwts_interactive.c
> +++ b/src/lib/src/fwts_interactive.c
> @@ -33,9 +33,11 @@ static int fwts_getchar(int *ch)
>  {
>  	struct termios oldterm;
>  	struct termios newterm;
> -	int fd = fileno(stdin);
> +	const int fd = fileno(stdin);
>  
>  	*ch = -1;
> +	if (fd < 0)
> +		return FWTS_ERROR;
>  
>  	if (tcgetattr(fd, &oldterm) < 0)
>  		return FWTS_ERROR;
> @@ -76,7 +78,7 @@ int fwts_printf(fwts_framework *fw, const char *fmt, ...)
>  }
>  
>  /*
> - *  fwts_press_entrer()
> + *  fwts_press_enter()
>   *	prompt and wait for enter key
>   */
>  int fwts_press_enter(fwts_framework *fw)
> @@ -111,7 +113,6 @@ int fwts_get_reply(fwts_framework *fw, const char *message, const char *options)
>  	fflush(stdout);
>  
>  	for (;;) {
> -
>  		if (fwts_getchar(&ch) == FWTS_ERROR) {
>  			fwts_log_error(fw, "fwts_getchar() failed.");
>  			break;
> @@ -124,4 +125,3 @@ int fwts_get_reply(fwts_framework *fw, const char *message, const char *options)
>  
>  	return ch;
>  }
> -

Acked-by: Ivan Hu <ivan.hu@canonical.com>
diff mbox series

Patch

diff --git a/src/lib/src/fwts_interactive.c b/src/lib/src/fwts_interactive.c
index 5a8e873e..d1aa70fe 100644
--- a/src/lib/src/fwts_interactive.c
+++ b/src/lib/src/fwts_interactive.c
@@ -33,9 +33,11 @@  static int fwts_getchar(int *ch)
 {
 	struct termios oldterm;
 	struct termios newterm;
-	int fd = fileno(stdin);
+	const int fd = fileno(stdin);
 
 	*ch = -1;
+	if (fd < 0)
+		return FWTS_ERROR;
 
 	if (tcgetattr(fd, &oldterm) < 0)
 		return FWTS_ERROR;
@@ -76,7 +78,7 @@  int fwts_printf(fwts_framework *fw, const char *fmt, ...)
 }
 
 /*
- *  fwts_press_entrer()
+ *  fwts_press_enter()
  *	prompt and wait for enter key
  */
 int fwts_press_enter(fwts_framework *fw)
@@ -111,7 +113,6 @@  int fwts_get_reply(fwts_framework *fw, const char *message, const char *options)
 	fflush(stdout);
 
 	for (;;) {
-
 		if (fwts_getchar(&ch) == FWTS_ERROR) {
 			fwts_log_error(fw, "fwts_getchar() failed.");
 			break;
@@ -124,4 +125,3 @@  int fwts_get_reply(fwts_framework *fw, const char *message, const char *options)
 
 	return ch;
 }
-