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