Date: Fri, 19 Feb 2016 15:06:12 -0800 From: Gleb Smirnoff <glebius@FreeBSD.org> To: Alan Somers <asomers@freebsd.org> Cc: Sergey Kandaurov <pluknet@gmail.com>, "svn-src-head@freebsd.org" <svn-src-head@freebsd.org>, "svn-src-all@freebsd.org" <svn-src-all@freebsd.org>, "src-committers@freebsd.org" <src-committers@freebsd.org> Subject: Re: svn commit: r295768 - head/usr.sbin/iostat Message-ID: <20160219230612.GR1945@FreeBSD.org> In-Reply-To: <CAOtMX2hyZ=GFgp8F6t0dMDYF5FSPdoP9KdMU7V5rmscpaPUnsw@mail.gmail.com> References: <201602182008.u1IK81vg092127@repo.freebsd.org> <CAE-mSO%2B7p=Equq81PPQjfZv1piPydBr4Mnk363CEs3w9EXRi9w@mail.gmail.com> <CAOtMX2hyZ=GFgp8F6t0dMDYF5FSPdoP9KdMU7V5rmscpaPUnsw@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Feb 19, 2016 at 08:49:43AM -0700, Alan Somers wrote: A> On Fri, Feb 19, 2016 at 5:24 AM, Sergey Kandaurov <pluknet@gmail.com> wrote: A> > On 18 February 2016 at 23:08, Alan Somers <asomers@freebsd.org> wrote: A> >> Author: asomers A> >> Date: Thu Feb 18 20:08:01 2016 A> >> New Revision: 295768 A> >> URL: https://svnweb.freebsd.org/changeset/base/295768 A> >> A> >> Log: A> >> Fix compiler warnings in iostat A> > A> >> Modified: head/usr.sbin/iostat/iostat.c A> >> ============================================================================== A> >> --- head/usr.sbin/iostat/iostat.c Thu Feb 18 19:37:39 2016 (r295767) A> >> +++ head/usr.sbin/iostat/iostat.c Thu Feb 18 20:08:01 2016 (r295768) A> >> @@ -117,30 +117,34 @@ A> >> #include <termios.h> A> >> #include <unistd.h> A> >> A> >> -struct nlist namelist[] = { A> >> +static struct nlist namelist[] = { A> >> #define X_TTY_NIN 0 A> >> - { "_tty_nin" }, A> >> + { .n_name = "_tty_nin", A> >> + .n_type = 0, .n_other = 0, .n_desc = 0, .n_value = 0 }, A> >> [...] A> > A> > You unlikely need this excessive explicit zeroization. A> > In this case it is implicitly prezeroed. A> > A> > Consider these two cases: A> > A> > : #include <nlist.h> A> > : A> > : int main(void) { A> > : struct nlist namelist[2] = {{ .n_type = 0x42 }}; A> > : return sizeof(namelist); A> > : } A> > A> > (__TEXT,__text) section A> > _main: A> > 0000000000000000 pushq %rbp A> > 0000000000000001 movq %rsp, %rbp A> > 0000000000000004 leaq -0x30(%rbp), %rdx A> > 0000000000000008 movl $0x0, %eax A> > 000000000000000d movl $0x6, %ecx A> > 0000000000000012 movq %rdx, %rdi A> > 0000000000000015 rep A> > 0000000000000016 stosq A> > 0000000000000018 movb $0x42, -0x28(%rbp) A> > 000000000000001c movl $0x30, %eax A> > 0000000000000021 popq %rbp A> > 0000000000000022 retq A> > A> > rep stosq does zero 48 bytes, that is namelist[]. A> > A> > Or, if it is static. A> > A> > : #include <nlist.h> A> > : A> > : int main(void) { A> > : static struct nlist namelist[2] = {{ .n_type = 0x42 }}; A> > : return sizeof(namelist); A> > : } A> > A> > (__DATA,__data) section A> > 0000000000000020 00 00 00 00 00 00 00 00 42 00 00 00 00 00 00 00 A> > 0000000000000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 A> > 0000000000000040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 A> A> Yeah, it was being implicitly zeroized before. But Clang complained A> about the structures being only partially initialized. Since the A> whole point of my commit was to increase the WARNS level, I explicitly A> zeroed the zero fields to silence Clang. Isn't zero filling part of the standard? I don't see why lack of explicit zeroing is a warning? Looks a false warning to me. -- Totus tuus, Glebius.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20160219230612.GR1945>