Re: [PATCH] range-diff: fix some 'hdr-check' and sparse warnings
- From
Carlo Arenas <carenas@gmail.com>
- Date
- Jul 13, 2019, 12:56 UTC
- Message-ID
- <CAPUEspgmkP_7K=eap3LpQSCp-k6HZ7FK-_LaBoBiJR1CqEMYmA@mail.gmail.com>
- In-Reply-To
- <ec635d0d-00ca-2419-3c1a-9b0343b46daa@kdbg.org>
On Sat, Jul 13, 2019 at 3:46 AM Johannes Sixt <j6t@kdbg.org> wrote:
>
> Using only = { 0 } for zero-initialization makes the code immune to
> rearrangements of the struct members.But only by forcing to set whichever is the first element to 0, which is exactly what sparse is complaining about, since it happens to be a pointer.
> That is not the case with = { NULL
> } because it requires that the first member is a pointer; if
> rearrangement makes the first member a non-pointer, the initializations
> must be adjusted.luckily sparse will complain loudly in that case as well as shown by:
$ cat t.c #include <stddef.h>
int main(int argc, char *argv[]) {
struct {
char i;
char *p;
} s = {NULL};
return 0;
}
$ sparse t.c
t.c:7:10: warning: incorrect type in initializer (different base types)
t.c:7:10: expected char i
t.c:7:10: got void *Carlo