From: Zbigniew Jędrzejewski-Szmek Date: Tue, 7 Jun 2022 08:52:19 +0000 (+0200) Subject: sd-hwdb: fix NULL arg to %s in error messages X-Git-Tag: v252-rc1~845^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9908091b960e1dbafa50ad88113bf24aa0b6ef4a;p=thirdparty%2Fsystemd.git 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. --- diff --git a/src/libsystemd/sd-hwdb/sd-hwdb.c b/src/libsystemd/sd-hwdb/sd-hwdb.c index f73d1fc21e0..51be54b1e14 100644 --- a/src/libsystemd/sd-hwdb/sd-hwdb.c +++ b/src/libsystemd/sd-hwdb/sd-hwdb.c @@ -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));