svn commit: r295768 - head/usr.sbin/iostat
Alan Somers
asomers at freebsd.org
Fri Feb 19 15:49:45 UTC 2016
On Fri, Feb 19, 2016 at 5:24 AM, Sergey Kandaurov <pluknet at gmail.com> wrote:
> On 18 February 2016 at 23:08, Alan Somers <asomers at 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
More information about the svn-src-all
mailing list