Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup: Explicitly initialize auto-cleanup variables #765

Merged
merged 4 commits into from
Jan 18, 2024

Conversation

tbzatek
Copy link
Contributor

@tbzatek tbzatek commented Dec 29, 2023

Using the default, slightly hardened CFLAGS in Fedora I was getting a bunch of warnings like

In file included from ../src/nvme/linux.c:38:
In function ‘cleanup_fd’,
    inlined from ‘__nvme_set_attr’ at ../src/nvme/linux.c:429:19,
    inlined from ‘nvme_set_attr’ at ../src/nvme/linux.c:451:9:
../src/nvme/cleanup.h:37:17: warning: ‘fd’ may be used uninitialized [-Wmaybe-uninitialized]
   37 |                 close(*fd);
      |                 ^~~~~~~~~~
../src/nvme/linux.c: In function ‘nvme_set_attr’:
../src/nvme/linux.c:429:26: note: ‘fd’ was declared here
  429 |         _cleanup_fd_ int fd ;
      |                          ^~

With a default meson build, these are not reported, despite that the project sets warning_level=1, i.e. -Wall. Stripping the CFLAGS down it turned out the two -O2 -fexceptions together will magically turn some extra warnings on. This is with gcc version 13.2.1 20231011.

gcc complains about potentially	uninitialized variables used
in the cleanup function even though such scenario is unlikely
to happen. Still, an explicit initializer makes the warnings
go away.

E.g.

../src/nvme/fabrics.c: In function ‘nvmf_hostnqn_generate’:
../src/nvme/fabrics.c:1297:30: note: ‘stream’ was declared here
 1297 |         _cleanup_file_ FILE *stream;
      |                              ^~~~~~
In function ‘cleanup_fd’,
    inlined from ‘uuid_from_device_tree’ at ../src/nvme/fabrics.c:1189:19,
    inlined from ‘nvmf_hostnqn_generate’ at ../src/nvme/fabrics.c:1350:9:
../src/nvme/cleanup.h:37:17: warning: ‘f’ may be used uninitialized [-Wmaybe-uninitialized]
   37 |                 close(*fd);
      |                 ^~~~~~~~~~

Signed-off-by: Tomas Bzatek <[email protected]>
gcc complains about potentially	uninitialized variables.

Signed-off-by: Tomas Bzatek <[email protected]>
gcc complains about potentially uninitialized variables.

Signed-off-by: Tomas Bzatek <[email protected]>
gcc complains about potentially uninitialized variables.

Signed-off-by: Tomas Bzatek <[email protected]>
@igaw igaw merged commit 267d2ab into linux-nvme:master Jan 18, 2024
13 of 14 checks passed
@igaw
Copy link
Collaborator

igaw commented Jan 18, 2024

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants