1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-23 21:35:11 +03:00

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)
      |                     ^~~~~~~~~~~~~~~~~~~
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2021-03-31 11:09:39 +02:00
parent befab2c40c
commit 55e2cfc938

View File

@ -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;
}