From owner-svn-src-all@freebsd.org Fri Feb 19 23:06:14 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 4E383AAE5A9; Fri, 19 Feb 2016 23:06:14 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from cell.glebi.us (glebi.us [96.95.210.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "cell.glebi.us", Issuer "cell.glebi.us" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 392561DE2; Fri, 19 Feb 2016 23:06:13 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from cell.glebi.us (localhost [127.0.0.1]) by cell.glebi.us (8.15.2/8.15.2) with ESMTPS id u1JN6CMN014637 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 19 Feb 2016 15:06:12 -0800 (PST) (envelope-from glebius@FreeBSD.org) Received: (from glebius@localhost) by cell.glebi.us (8.15.2/8.15.2/Submit) id u1JN6CMP014636; Fri, 19 Feb 2016 15:06:12 -0800 (PST) (envelope-from glebius@FreeBSD.org) X-Authentication-Warning: cell.glebi.us: glebius set sender to glebius@FreeBSD.org using -f Date: Fri, 19 Feb 2016 15:06:12 -0800 From: Gleb Smirnoff To: Alan Somers Cc: Sergey Kandaurov , "svn-src-head@freebsd.org" , "svn-src-all@freebsd.org" , "src-committers@freebsd.org" Subject: Re: svn commit: r295768 - head/usr.sbin/iostat Message-ID: <20160219230612.GR1945@FreeBSD.org> References: <201602182008.u1IK81vg092127@repo.freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 19 Feb 2016 23:06:14 -0000 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 wrote: A> > On 18 February 2016 at 23:08, Alan Somers 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 A> >> #include 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 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 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.