diff mbox series

lib: fwts_tty: memset a ws struct to keep static analyzers happy

Message ID 20200407160708.882318-1-colin.king@canonical.com
State Accepted
Headers show
Series lib: fwts_tty: memset a ws struct to keep static analyzers happy | expand

Commit Message

Colin Ian King April 7, 2020, 4:07 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

Coverity throws a warning of a potential use of unitialized fields
in the ws struct, so memset it to zero before calling the ioctl.

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

Comments

Alex Hung April 7, 2020, 4:27 p.m. UTC | #1
On 2020-04-07 10:07 a.m., Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Coverity throws a warning of a potential use of unitialized fields
> in the ws struct, so memset it to zero before calling the ioctl.
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/src/fwts_tty.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/src/lib/src/fwts_tty.c b/src/lib/src/fwts_tty.c
> index 1ed881dc..15c911e7 100644
> --- a/src/lib/src/fwts_tty.c
> +++ b/src/lib/src/fwts_tty.c
> @@ -18,6 +18,7 @@
>   */
>  #include <sys/ioctl.h>
>  #include <unistd.h>
> +#include <string.h>
>  
>  /*
>   *  fwts_tty_width()
> @@ -29,6 +30,8 @@ int fwts_tty_width(const int fd, const int default_width)
>  #ifdef TIOCGWINSZ
>  	struct winsize ws;
>  
> +	/* Zero'ing ws keeps static analyzers happy */
> +	(void)memset(&ws, 0, sizeof(ws));
>  	/* if tty and we can get a sane width, return it */
>  	if (isatty(fd) &&
>  	    (ioctl(fd, TIOCGWINSZ, &ws) != -1) &&
> 


Acked-by: Alex Hung <alex.hung@canonical.com>
Ivan Hu April 8, 2020, 6:42 a.m. UTC | #2
On 4/8/20 12:07 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Coverity throws a warning of a potential use of unitialized fields
> in the ws struct, so memset it to zero before calling the ioctl.
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/src/fwts_tty.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/src/lib/src/fwts_tty.c b/src/lib/src/fwts_tty.c
> index 1ed881dc..15c911e7 100644
> --- a/src/lib/src/fwts_tty.c
> +++ b/src/lib/src/fwts_tty.c
> @@ -18,6 +18,7 @@
>   */
>  #include <sys/ioctl.h>
>  #include <unistd.h>
> +#include <string.h>
>  
>  /*
>   *  fwts_tty_width()
> @@ -29,6 +30,8 @@ int fwts_tty_width(const int fd, const int default_width)
>  #ifdef TIOCGWINSZ
>  	struct winsize ws;
>  
> +	/* Zero'ing ws keeps static analyzers happy */
> +	(void)memset(&ws, 0, sizeof(ws));
>  	/* if tty and we can get a sane width, return it */
>  	if (isatty(fd) &&
>  	    (ioctl(fd, TIOCGWINSZ, &ws) != -1) &&
> 


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

Patch

diff --git a/src/lib/src/fwts_tty.c b/src/lib/src/fwts_tty.c
index 1ed881dc..15c911e7 100644
--- a/src/lib/src/fwts_tty.c
+++ b/src/lib/src/fwts_tty.c
@@ -18,6 +18,7 @@ 
  */
 #include <sys/ioctl.h>
 #include <unistd.h>
+#include <string.h>
 
 /*
  *  fwts_tty_width()
@@ -29,6 +30,8 @@  int fwts_tty_width(const int fd, const int default_width)
 #ifdef TIOCGWINSZ
 	struct winsize ws;
 
+	/* Zero'ing ws keeps static analyzers happy */
+	(void)memset(&ws, 0, sizeof(ws));
 	/* if tty and we can get a sane width, return it */
 	if (isatty(fd) &&
 	    (ioctl(fd, TIOCGWINSZ, &ws) != -1) &&