1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-26 10:03:40 +03:00

sd-hwdb: fix NULL arg to %s in error messages

gcc warns about $subject, and it is obviously correct. path may or
may not be set.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2022-06-07 10:52:19 +02:00
parent 6c279977e3
commit 9908091b96

View File

@ -283,7 +283,6 @@ static int trie_search_f(sd_hwdb *hwdb, const char *search) {
static int hwdb_new(const char *path, sd_hwdb **ret) {
_cleanup_(sd_hwdb_unrefp) sd_hwdb *hwdb = NULL;
const char *hwdb_bin_path = NULL;
const char sig[] = HWDB_SIG;
assert_return(ret, -EINVAL);
@ -294,20 +293,20 @@ static int hwdb_new(const char *path, sd_hwdb **ret) {
hwdb->n_ref = 1;
/* find hwdb.bin in hwdb_bin_paths, or from an explicit path if provided */
/* Find hwdb.bin in the explicit path if provided, or iterate over hwdb_bin_paths otherwise */
if (!isempty(path)) {
log_debug("Trying to open \"%s\"...", path);
hwdb->f = fopen(path, "re");
if (!hwdb->f)
return log_debug_errno(errno, "Failed to open %s: %m", path);
} else {
NULSTR_FOREACH(hwdb_bin_path, hwdb_bin_paths) {
log_debug("Trying to open \"%s\"...", hwdb_bin_path);
hwdb->f = fopen(hwdb_bin_path, "re");
NULSTR_FOREACH(path, hwdb_bin_paths) {
log_debug("Trying to open \"%s\"...", path);
hwdb->f = fopen(path, "re");
if (hwdb->f)
break;
if (errno != ENOENT)
return log_debug_errno(errno, "Failed to open %s: %m", hwdb_bin_path);
return log_debug_errno(errno, "Failed to open %s: %m", path);
}
if (!hwdb->f)
@ -316,23 +315,20 @@ static int hwdb_new(const char *path, sd_hwdb **ret) {
}
if (fstat(fileno(hwdb->f), &hwdb->st) < 0)
return log_debug_errno(errno, "Failed to stat %s: %m", hwdb_bin_path);
return log_debug_errno(errno, "Failed to stat %s: %m", path);
if (hwdb->st.st_size < (off_t) offsetof(struct trie_header_f, strings_len) + 8)
return log_debug_errno(SYNTHETIC_ERRNO(EIO),
"File %s is too short: %m", hwdb_bin_path);
return log_debug_errno(SYNTHETIC_ERRNO(EIO), "File %s is too short: %m", path);
if (file_offset_beyond_memory_size(hwdb->st.st_size))
return log_debug_errno(SYNTHETIC_ERRNO(EFBIG),
"File %s is too long: %m", hwdb_bin_path);
return log_debug_errno(SYNTHETIC_ERRNO(EFBIG), "File %s is too long: %m", path);
hwdb->map = mmap(0, hwdb->st.st_size, PROT_READ, MAP_SHARED, fileno(hwdb->f), 0);
if (hwdb->map == MAP_FAILED)
return log_debug_errno(errno, "Failed to map %s: %m", hwdb_bin_path);
return log_debug_errno(errno, "Failed to map %s: %m", path);
if (memcmp(hwdb->map, sig, sizeof(hwdb->head->signature)) != 0 ||
(size_t) hwdb->st.st_size != le64toh(hwdb->head->file_size))
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
"Failed to recognize the format of %s",
hwdb_bin_path);
"Failed to recognize the format of %s", path);
log_debug("=== trie on-disk ===");
log_debug("tool version: %"PRIu64, le64toh(hwdb->head->tool_version));