diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-05-18 02:18:49 +0200 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-05-21 17:53:57 +0200 |
| commit | 537e3e2daebd37d69447e65535fc94e82b38fc18 (patch) | |
| tree | cbc2e143ad063784905371f9071f7196757c8c68 /validation | |
| parent | 850c8625ae784a08094f30dde9c85b74e369bacd (diff) | |
| download | sparse-dev-537e3e2daebd37d69447e65535fc94e82b38fc18.tar.gz | |
univ-init: conditionally accept { 0 } without warnings
In standard C '{ 0 }' is valid to initialize any compound object.
OTOH, Sparse allows '{ }' for the same purpose but:
1) '{ }' is not standard
2) Sparse warns when using '0' to initialize pointers.
Some projects (git) legitimately like to be able to use the
standard '{ 0 }' without the null-pointer warnings
So, add a new warning flag (-Wno-universal-initializer) to
handle '{ 0 }' as '{ }', suppressing the warnings.
Reference: https://lore.kernel.org/git/1df91aa4-dda5-64da-6ae3-5d65e50a55c5@ramsayjones.plus.com/
Reference: https://lore.kernel.org/git/e6796c60-a870-e761-3b07-b680f934c537@ramsayjones.plus.com/
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'validation')
| -rw-r--r-- | validation/Wuniv-init-ko.c | 14 | ||||
| -rw-r--r-- | validation/Wuniv-init-ok.c | 11 |
2 files changed, 25 insertions, 0 deletions
diff --git a/validation/Wuniv-init-ko.c b/validation/Wuniv-init-ko.c new file mode 100644 index 00000000..315c211a --- /dev/null +++ b/validation/Wuniv-init-ko.c @@ -0,0 +1,14 @@ +struct s { + void *ptr; +}; + + +static struct s s = { 0 }; + +/* + * check-name: univ-init-ko + * + * check-error-start +Wuniv-init-ko.c:6:23: warning: Using plain integer as NULL pointer + * check-error-end + */ diff --git a/validation/Wuniv-init-ok.c b/validation/Wuniv-init-ok.c new file mode 100644 index 00000000..c3964751 --- /dev/null +++ b/validation/Wuniv-init-ok.c @@ -0,0 +1,11 @@ +struct s { + void *ptr; +}; + + +static struct s s = { 0 }; + +/* + * check-name: univ-init-ok + * check-command: sparse -Wno-universal-initializer $file + */ |
