Skip to content

Commit a681e83

Browse files
tbzatekigaw
authored andcommitted
fabrics: Explicitly initialize auto-cleanup variables
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]>
1 parent d1f4c66 commit a681e83

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

src/nvme/fabrics.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ static int __nvmf_supported_options(nvme_root_t r)
740740

741741
static int __nvmf_add_ctrl(nvme_root_t r, const char *argstr)
742742
{
743-
_cleanup_fd_ int fd;
743+
_cleanup_fd_ int fd = -1;
744744
int ret, len = strlen(argstr);
745745
char buf[0x1000], *options, *p;
746746

@@ -1186,7 +1186,7 @@ struct nvmf_discovery_log *nvmf_get_discovery_wargs(struct nvme_get_discovery_ar
11861186
static int uuid_from_device_tree(char *system_uuid)
11871187
{
11881188
ssize_t len;
1189-
_cleanup_fd_ int f;
1189+
_cleanup_fd_ int f = -1;
11901190

11911191
f = open(PATH_UUID_IBM, O_RDONLY);
11921192
if (f < 0)
@@ -1230,7 +1230,7 @@ static bool is_dmi_uuid_valid(const char *buf, size_t len)
12301230
static int uuid_from_dmi_entries(char *system_uuid)
12311231
{
12321232
int f;
1233-
_cleanup_dir_ DIR *d;
1233+
_cleanup_dir_ DIR *d = NULL;
12341234
struct dirent *de;
12351235
char buf[512] = {0};
12361236

@@ -1294,7 +1294,7 @@ static int uuid_from_dmi_entries(char *system_uuid)
12941294
*/
12951295
static int uuid_from_product_uuid(char *system_uuid)
12961296
{
1297-
_cleanup_file_ FILE *stream;
1297+
_cleanup_file_ FILE *stream = NULL;
12981298
ssize_t nread;
12991299
_cleanup_free_ char *line = NULL;
13001300
size_t len = 0;
@@ -1364,7 +1364,7 @@ char *nvmf_hostnqn_generate()
13641364
static char *nvmf_read_file(const char *f, int len)
13651365
{
13661366
char buf[len];
1367-
_cleanup_fd_ int fd;
1367+
_cleanup_fd_ int fd = -1;
13681368
int ret;
13691369

13701370
fd = open(f, O_RDONLY);
@@ -1637,7 +1637,7 @@ static const char *dctype_str[] = {
16371637
*/
16381638
static int nvme_fetch_cntrltype_dctype_from_id(nvme_ctrl_t c)
16391639
{
1640-
_cleanup_free_ struct nvme_id_ctrl *id;
1640+
_cleanup_free_ struct nvme_id_ctrl *id = NULL;
16411641
int ret;
16421642

16431643
id = __nvme_alloc(sizeof(*id));

0 commit comments

Comments
 (0)