From cbe97b9c92728e96c9987314a7e1e05bbdffda16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 14 Apr 2021 06:05:47 -0400 Subject: [PATCH] basic/log: force log_*_errno() to return negative This silences some warnigns where gcc thinks that some variables are unitialized. One particular case: ../src/journal/journald-server.c: In function 'ache_space_refresh': ../src/journal/journald-server.c:136:28: error: 'vfs_avail' may be used uninitialized in this function [-Werror=maybe-uninitialized] 136 | uint64_t vfs_used, vfs_avail, avail; | ^~~~~~~~~ ../src/journal/journald-server.c:136:18: error: 'vfs_used' may be used uninitialized in this function [-Werror=maybe-uninitialized] 136 | uint64_t vfs_used, vfs_avail, avail; | ^~~~~~~~ cc1: all warnings being treated as errors which is caused by d = opendir(path); if (!d) return log_full_errno(errno == ENOENT ? LOG_DEBUG : LOG_ERR, errno, "Failed to open %s: %m", path); if (fstatvfs(dirfd(d), &ss) < 0) return log_error_errno(errno, "Failed to fstatvfs(%s): %m", path); For some reason on aarch64 gcc thinks we might return non-negative here. In principle errno must be set in both cases, but it's hard to say for certain. So let's make sure that our code flow is correct, even if somebody forgot to set the global variable somewhere. --- src/basic/log.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/basic/log.h b/src/basic/log.h index b3d32abfc8..4b621097d4 100644 --- a/src/basic/log.h +++ b/src/basic/log.h @@ -191,9 +191,10 @@ void log_assert_failed_return( #define log_full_errno(level, error, ...) \ ({ \ int _level = (level), _e = (error); \ - (log_get_max_level() >= LOG_PRI(_level)) \ + _e = (log_get_max_level() >= LOG_PRI(_level)) \ ? log_internal(_level, _e, PROJECT_FILE, __LINE__, __func__, __VA_ARGS__) \ : -ERRNO_VALUE(_e); \ + _e < 0 ? _e : -EIO; \ }) #define log_full(level, ...) (void) log_full_errno((level), 0, __VA_ARGS__)