]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fileio: use take_fdopen_unlocked()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 16 Apr 2021 01:08:36 +0000 (10:08 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 16 Apr 2021 15:22:12 +0000 (00:22 +0900)
This fixes maybe-uninitialized warning:
```
../src/basic/fileio.c: In function ‘chase_symlinks_and_fopen_unlocked’:
../src/basic/fileio.c:1026:19: warning: ‘f’ may be used uninitialized in this function [-Wmaybe-uninitialized]
 1026 |         *ret_file = f;
      |         ~~~~~~~~~~^~~

```

src/basic/fileio.c

index adfde64cbc8d71292450eb39089040dab47de9bc..414fd15d567c6296de5d6b9aaac81f39713cf82c 100644 (file)
@@ -57,7 +57,7 @@ int fdopen_unlocked(int fd, const char *options, FILE **ret) {
 }
 
 int take_fdopen_unlocked(int *fd, const char *options, FILE **ret) {
-        int     r;
+        int r;
 
         assert(fd);
 
@@ -1004,7 +1004,6 @@ int chase_symlinks_and_fopen_unlocked(
         _cleanup_close_ int fd = -1;
         _cleanup_free_ char *final_path = NULL;
         int mode_flags, r;
-        FILE *f;
 
         assert(path);
         assert(open_flags);
@@ -1018,12 +1017,10 @@ int chase_symlinks_and_fopen_unlocked(
         if (fd < 0)
                 return fd;
 
-        r = fdopen_unlocked(fd, open_flags, &f);
+        r = take_fdopen_unlocked(&fd, open_flags, ret_file);
         if (r < 0)
                 return r;
-        TAKE_FD(fd);
 
-        *ret_file = f;
         if (ret_path)
                 *ret_path = TAKE_PTR(final_path);
         return 0;