From: Zbigniew Jędrzejewski-Szmek Date: Wed, 31 Mar 2021 09:09:39 +0000 (+0200) Subject: basic/fileio: silence gcc's maybe-unitialized warning X-Git-Tag: v249-rc1~490^2~14 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=55e2cfc9387ddf36fe115ae445b9a58fd5d3b89c;p=thirdparty%2Fsystemd.git basic/fileio: silence gcc's maybe-unitialized warning [11/657] Compiling C object src/basic/libbasic.a.p/fileio.c.o ../src/basic/fileio.c: In function ‘write_string_stream_ts’: ../src/basic/fileio.c:167:21: warning: ‘fd’ may be used uninitialized in this function [-Wmaybe-uninitialized] 167 | if (futimens(fd, twice) < 0) | ^~~~~~~~~~~~~~~~~~~ --- diff --git a/src/basic/fileio.c b/src/basic/fileio.c index df30870a1a2..abd822796e7 100644 --- a/src/basic/fileio.c +++ b/src/basic/fileio.c @@ -121,7 +121,7 @@ int write_string_stream_ts( const struct timespec *ts) { bool needs_nl; - int r, fd; + int r, fd = -1; assert(f); assert(line); @@ -140,8 +140,8 @@ int write_string_stream_ts( needs_nl = !(flags & WRITE_STRING_FILE_AVOID_NEWLINE) && !endswith(line, "\n"); if (needs_nl && (flags & WRITE_STRING_FILE_DISABLE_BUFFER)) { - /* If STDIO buffering was disabled, then let's append the newline character to the string itself, so - * that the write goes out in one go, instead of two */ + /* If STDIO buffering was disabled, then let's append the newline character to the string + * itself, so that the write goes out in one go, instead of two */ line = strjoina(line, "\n"); needs_nl = false; @@ -164,6 +164,7 @@ int write_string_stream_ts( if (ts) { const struct timespec twice[2] = {*ts, *ts}; + assert(fd >= 0); if (futimens(fd, twice) < 0) return -errno; }