svn commit: r295768 - head/usr.sbin/iostat

Gleb Smirnoff glebius at FreeBSD.org
Fri Feb 19 23:06:14 UTC 2016


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 at gmail.com> wrote:
A> > On 18 February 2016 at 23:08, Alan Somers <asomers at 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.


More information about the svn-src-head mailing list