]> www.infradead.org Git - users/sagi/libnvme.git/commitdiff
util: Explicitly initialize auto-cleanup variables
authorTomas Bzatek <tbzatek@redhat.com>
Fri, 29 Dec 2023 17:49:44 +0000 (18:49 +0100)
committerDaniel Wagner <wagi@monom.org>
Thu, 18 Jan 2024 10:35:14 +0000 (11:35 +0100)
gcc complains about potentially uninitialized variables.

Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
src/nvme/util.c

index 78ce14f89d1d66d0c5cb54b8226910e62432022c..f091da70cecdfbb355af664e5d0d66341af17b75 100644 (file)
@@ -757,7 +757,7 @@ char *kv_keymatch(const char *kv, const char *key)
 static size_t read_file(const char * fname, char *buffer, size_t *bufsz)
 {
        char   *p;
-       _cleanup_file_ FILE *file;
+       _cleanup_file_ FILE *file = NULL;
        size_t len;
 
        file = fopen(fname, "re");
@@ -806,7 +806,7 @@ size_t get_entity_name(char *buffer, size_t bufsz)
 
 size_t get_entity_version(char *buffer, size_t bufsz)
 {
-       _cleanup_file_ FILE *file;
+       _cleanup_file_ FILE *file = NULL;
        size_t  num_bytes = 0;
 
        /* /proc/sys/kernel/ostype typically contains the string "Linux" */
@@ -928,7 +928,7 @@ int nvme_uuid_from_string(const char *str, unsigned char uuid[NVME_UUID_LEN])
 
 int nvme_uuid_random(unsigned char uuid[NVME_UUID_LEN])
 {
-       _cleanup_fd_ int f;
+       _cleanup_fd_ int f = -1;
        ssize_t n;
 
        f = open("/dev/urandom", O_RDONLY);