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 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 { }.

                 Linus




[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