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 |
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>
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 --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) &&