[PATCH] lib: fwts_tty: memset a ws struct to keep static analyzers happy
Colin King
colin.king at canonical.com
Tue Apr 7 16:07:08 UTC 2020
From: Colin Ian King <colin.king at 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 at 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) &&
--
2.25.1
More information about the fwts-devel
mailing list