]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic/tmpfile: avoid maybe-uninitialized warning in mkostemp_safe()
authorThomas Haller <thaller@redhat.com>
Sun, 15 Dec 2019 14:50:43 +0000 (15:50 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 16 Dec 2019 13:25:31 +0000 (14:25 +0100)
The variable is always initialized, but the compiler might not notice
that. With gcc-9.2.1-1.fc31:

    $ CFLAGS='-Werror=maybe-uninitialized -Og' meson build
    $ ninja -C build
    [...]
    ../src/basic/tmpfile-util.c: In function ‘mkostemp_safe’:
    ../src/basic/tmpfile-util.c:76:12: error: ‘fd’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
       76 |         if (fd < 0)
          |            ^

src/basic/tmpfile-util.c

index 2d201e1a57f34d918e7a84c3a6d3d437d7306f2c..decdafb9c958159b1ef0c1ec2db32e90c57c71f8 100644 (file)
@@ -67,7 +67,7 @@ int fopen_temporary(const char *path, FILE **ret_f, char **ret_temp_path) {
 
 /* This is much like mkostemp() but is subject to umask(). */
 int mkostemp_safe(char *pattern) {
-        int fd;
+        int fd = -1; /* avoid false maybe-uninitialized warning */
 
         assert(pattern);