Re: "Using plain integer as NULL pointer" false positive for zero struct initializer

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 09/01/2019 17:54, Linus Torvalds wrote:
> On Wed, Jan 9, 2019 at 6:58 AM Aurélien Aptel <aaptel@xxxxxxxx> wrote:
>>
>> We have the following piece of code in fs/cifs/connect.c (linux):
>>
>>         struct smb_vol fake_vol = {0};
>>
>> Where smb_vol is a struct containing pointers. AFAIK this construct is
>> valid so I think it's a bug. Sorry for the noise if this has already
>> been reported.
> 
> It is valid, but so is
> 
>     void *a = 0;
> 
> and sparse warns for that too.
> 
> It's also valid to say
> 
>          struct smb_vol fake_vol = { };
> 
> which initializes the struct to empty too, and doesn't get a sparse warning.
> 
> Put another way: if you know the first field is a pointer, just use {
> NULL }. And if you don't know what is the first member, or don't care,
> use { }.

I was just about to reply with similar comments (along with some
commentary on explicit/implicit initialization and designated
initializers, etc). However, I was going to say that it is a
shame that the C language does not allow an empty initializer
list (ie {}) as that would be my preferred solution! ;-)

Ahem, so yes, both gcc and clang allow this (I just tested it), but
my reading of the C99 standard lead me to believe that this is not
valid C. (Not that it really matters).

ATB,
Ramsay Jones



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux