mirror of
https://github.com/systemd/systemd.git
synced 2025-09-02 17:49:53 +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:
@ -121,7 +121,7 @@ int write_string_stream_ts(
|
|||||||
const struct timespec *ts) {
|
const struct timespec *ts) {
|
||||||
|
|
||||||
bool needs_nl;
|
bool needs_nl;
|
||||||
int r, fd;
|
int r, fd = -1;
|
||||||
|
|
||||||
assert(f);
|
assert(f);
|
||||||
assert(line);
|
assert(line);
|
||||||
@ -140,8 +140,8 @@ int write_string_stream_ts(
|
|||||||
needs_nl = !(flags & WRITE_STRING_FILE_AVOID_NEWLINE) && !endswith(line, "\n");
|
needs_nl = !(flags & WRITE_STRING_FILE_AVOID_NEWLINE) && !endswith(line, "\n");
|
||||||
|
|
||||||
if (needs_nl && (flags & WRITE_STRING_FILE_DISABLE_BUFFER)) {
|
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
|
/* If STDIO buffering was disabled, then let's append the newline character to the string
|
||||||
* that the write goes out in one go, instead of two */
|
* itself, so that the write goes out in one go, instead of two */
|
||||||
|
|
||||||
line = strjoina(line, "\n");
|
line = strjoina(line, "\n");
|
||||||
needs_nl = false;
|
needs_nl = false;
|
||||||
@ -164,6 +164,7 @@ int write_string_stream_ts(
|
|||||||
if (ts) {
|
if (ts) {
|
||||||
const struct timespec twice[2] = {*ts, *ts};
|
const struct timespec twice[2] = {*ts, *ts};
|
||||||
|
|
||||||
|
assert(fd >= 0);
|
||||||
if (futimens(fd, twice) < 0)
|
if (futimens(fd, twice) < 0)
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user