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 09, 2019 at 03:57:56PM +0100, Aurélien Aptel wrote:
> Hi,
> 
> 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.

Hi,

Yes, this is valid/legal C, no discussion about it.
But I think that a lot, if not most, GCC's (and other compiler's)
*warnings* are about valid constructions which are considered as
dangerous, obsolete, possibly buggy, ...
For the present case, sparse gives a warnings because the goal is
to prevent a possible type error by using an integer as a pointer.
Stricter type checking is, essentially, sparse's "raison d'être".

The best should be to be able to use { } since it would do the
default-initialize for all members without having to know their
type and their order but as others have already noticed this is
not valid C. This is an error in the standard, IMO.
So if you want to use strictly standard C and avoid the warning
you have to use '{ NULL }'.

Best regards,
-- Luc



[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