From: Michael Tremer Date: Thu, 18 Aug 2022 10:43:00 +0000 (+0000) Subject: string: Correct handle return code of pakfire_string_set/_format X-Git-Tag: 0.9.28~450 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a60955af8013128d9b64afa1507a0df2b59d197b;p=pakfire.git string: Correct handle return code of pakfire_string_set/_format Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/archive.c b/src/libpakfire/archive.c index 3a0c8531b..53f8c50b7 100644 --- a/src/libpakfire/archive.c +++ b/src/libpakfire/archive.c @@ -394,7 +394,7 @@ static int pakfire_archive_add_chksum(struct pakfire_archive* archive, const cha // Store path r = pakfire_string_set(chksum->path, path); - if (r < 0) + if (r) goto ERROR; // SHA512 @@ -878,8 +878,11 @@ PAKFIRE_EXPORT int pakfire_archive_extract(struct pakfire_archive* archive) { DEBUG(archive->pakfire, "Extracting %s\n", archive->path); // Set prefix for source packages - if (pakfire_package_is_source(pkg)) - pakfire_string_format(prefix, "/usr/src/packages/%s", nevra); + if (pakfire_package_is_source(pkg)) { + r = pakfire_string_format(prefix, "/usr/src/packages/%s", nevra); + if (r) + goto ERROR; + } // Open payload payload = pakfire_archive_open_payload(archive, &a, &size); @@ -1140,14 +1143,14 @@ static int pakfire_archive_load_checksums_legacy_line( // path case 0: r = pakfire_string_set(path, word); - if (r < 0) + if (r) return r; break; // hexdigest case 1: r = pakfire_string_set(hexdigest, word); - if (r < 0) + if (r) return r; break; @@ -1799,8 +1802,8 @@ static int pakfire_archive_append_signature(struct pakfire_archive* archive, // Make filename r = pakfire_string_format(path, "signatures/%s", pakfire_key_get_fingerprint(key)); - if (r < 0) - return 1; + if (r) + return r; // Create a new file entry struct archive_entry* entry = archive_entry_new(); diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index 044bce819..fe4c96c74 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -507,7 +507,7 @@ static int pakfire_build_package_add_scriptlets(struct pakfire_build* build, for (const char** type = pakfire_scriptlet_types; *type; type++) { r = pakfire_string_format(name, "scriptlet:%s", *type); - if (r < 0) + if (r) return r; // Fetch the scriptlet @@ -668,7 +668,7 @@ static int pakfire_build_stage(struct pakfire_build* build, // Prepare template for this stage int r = pakfire_string_format(template, TEMPLATE, stage); - if (r < 0) + if (r) return r; // Fetch the environment @@ -819,7 +819,7 @@ static int pakfire_build_setup_cgroup(struct pakfire_build* build) { // Compose path r = pakfire_string_format(path, "pakfire/build-%s", build->_id); - if (r < 0) { + if (r) { ERROR(build->pakfire, "Could not compose path for cgroup: %m\n"); return 1; } @@ -1011,9 +1011,7 @@ PAKFIRE_EXPORT struct pakfire_build* pakfire_build_unref(struct pakfire_build* b PAKFIRE_EXPORT int pakfire_build_set_target( struct pakfire_build* build, const char* target) { - pakfire_string_set(build->target, target); - - return 0; + return pakfire_string_set(build->target, target); } static int pakfire_build_install_packages(struct pakfire_build* build, @@ -1154,8 +1152,8 @@ static int pakfire_build_read_makefile(struct pakfire_build* build, // Compose path to makefile r = pakfire_string_format(makefile, "/usr/src/packages/%s/%s.nm", nevra, name); - if (r < 0) - return 1; + if (r) + return r; // Make it absolute r = pakfire_make_path(build->pakfire, path, makefile); diff --git a/src/libpakfire/config.c b/src/libpakfire/config.c index c9b3b6c78..ad1095f73 100644 --- a/src/libpakfire/config.c +++ b/src/libpakfire/config.c @@ -104,17 +104,13 @@ static struct pakfire_config_entry* pakfire_config_create_entry( // Store section r = pakfire_string_set(entry->section, section); - if (r < 0) { - errno = ENOBUFS; + if (r) goto ERROR; - } // Store key r = pakfire_string_set(entry->key, key); - if (r < 0) { - errno = ENOBUFS; + if (r) goto ERROR; - } // Append it to the list of entries STAILQ_INSERT_TAIL(&config->entries, entry, nodes); @@ -170,11 +166,7 @@ int pakfire_config_set(struct pakfire_config* config, } // Store the value - int r = pakfire_string_set(entry->value, value); - if (r < 0) - return r; - - return 0; + return pakfire_string_set(entry->value, value); } const char* pakfire_config_get(struct pakfire_config* config, diff --git a/src/libpakfire/downloader.c b/src/libpakfire/downloader.c index 70605950f..36a01fe7f 100644 --- a/src/libpakfire/downloader.c +++ b/src/libpakfire/downloader.c @@ -756,7 +756,7 @@ static int pakfire_downloader_prepare_transfer(struct pakfire_downloader* downlo if (!transfer->f) { // Make path for the temporary file (must be on the same file system) r = pakfire_string_format(transfer->tempfile, "%s.XXXXXX", transfer->path); - if (r < 0) + if (r) return 1; transfer->f = pakfire_mktemp(transfer->tempfile); diff --git a/src/libpakfire/file.c b/src/libpakfire/file.c index 7120ef44c..43497f972 100644 --- a/src/libpakfire/file.c +++ b/src/libpakfire/file.c @@ -526,7 +526,7 @@ int pakfire_file_cleanup(struct pakfire_file* file) { // Create a working copy of abspath r = pakfire_string_set(path, file->abspath); - if (r < 0) + if (r) return r; // See how many levels this file has diff --git a/src/libpakfire/jail.c b/src/libpakfire/jail.c index f2aac5fd6..3686c0a4d 100644 --- a/src/libpakfire/jail.c +++ b/src/libpakfire/jail.c @@ -925,16 +925,16 @@ PAKFIRE_EXPORT int pakfire_jail_bind(struct pakfire_jail* jail, // Copy source r = pakfire_string_set(mp->source, source); - if (r < 0) { + if (r) { ERROR(jail->pakfire, "Could not copy source: %m\n"); - return 1; + return r; } // Copy target r = pakfire_string_set(mp->target, target); - if (r < 0) { + if (r) { ERROR(jail->pakfire, "Could not copy target: %m\n"); - return 1; + return r; } // Copy flags @@ -998,8 +998,8 @@ static int pakfire_jail_setup_uid_mapping(struct pakfire_jail* jail, pid_t pid) // Make path r = pakfire_string_format(path, "/proc/%d/uid_map", pid); - if (r < 0) - return 1; + if (r) + return r; DEBUG(jail->pakfire, "Mapping UID range (%u - %lu)\n", subuid->id, subuid->id + subuid->length); @@ -1022,8 +1022,8 @@ static int pakfire_jail_setup_gid_mapping(struct pakfire_jail* jail, pid_t pid) // Make path r = pakfire_string_format(path, "/proc/%d/gid_map", pid); - if (r < 0) - return 1; + if (r) + return r; DEBUG(jail->pakfire, "Mapping GID range (%u - %lu)\n", subgid->id, subgid->id + subgid->length); @@ -1037,8 +1037,8 @@ static int pakfire_jail_setgroups(struct pakfire_jail* jail, pid_t pid) { // Make path r = pakfire_string_format(path, "/proc/%d/setgroups", pid); - if (r < 0) - return 1; + if (r) + return r; // Open file for writing FILE* f = fopen(path, "w"); diff --git a/src/libpakfire/key.c b/src/libpakfire/key.c index 66f52ac03..50b83dd47 100644 --- a/src/libpakfire/key.c +++ b/src/libpakfire/key.c @@ -378,7 +378,7 @@ static int pakfire_key_write_to_keystore(struct pakfire_key* key) { // Make path int r = pakfire_string_format(path, "%s/%s.key", keystore_path, fpr); - if (r < 0) + if (r) return r; // Create parent directory diff --git a/src/libpakfire/packager.c b/src/libpakfire/packager.c index ad10c1afe..e18bf54af 100644 --- a/src/libpakfire/packager.c +++ b/src/libpakfire/packager.c @@ -571,7 +571,7 @@ static int pakfire_packager_write_scriptlet(struct pakfire_packager* packager, // Make filename r = pakfire_string_format(filename, "scriptlet/%s", type); - if (r < 0) + if (r) return r; // Fetch scriptlet @@ -749,7 +749,7 @@ int pakfire_packager_finish_to_directory(struct pakfire_packager* packager, // Make the package path r = pakfire_string_format(path, "%s/%s", target, filename); - if (r < 0) + if (r) goto ERROR; // Create the parent directory @@ -759,7 +759,7 @@ int pakfire_packager_finish_to_directory(struct pakfire_packager* packager, // Create a temporary file in the target directory r = pakfire_string_format(tmppath, "%s.XXXXXX", path); - if (r < 0) + if (r) goto ERROR; // Create a temporary result file diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index a13a861e6..8fcd7a09f 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -636,7 +636,7 @@ static int pakfire_read_os_release(struct pakfire* pakfire) { continue; // Catch any errors - if (r < 0) + if (r) goto ERROR; } diff --git a/src/libpakfire/progressbar.c b/src/libpakfire/progressbar.c index 01edfcb34..ce9211c22 100644 --- a/src/libpakfire/progressbar.c +++ b/src/libpakfire/progressbar.c @@ -450,7 +450,7 @@ PAKFIRE_EXPORT int pakfire_progressbar_add_string(struct pakfire_progressbar* p, static const char* pakfire_progressbar_counter(struct pakfire_progressbar* p, struct pakfire_progressbar_widget* widget, unsigned int width, void* data) { int r = pakfire_string_format(widget->buffer, "%lu/%lu", p->value, p->value_max); - if (r < 0) + if (r) return NULL; return widget->buffer; @@ -467,7 +467,7 @@ static const char* pakfire_progressbar_percentage(struct pakfire_progressbar* p, double percentage = p->value * 100.0 / p->value_max; int r = pakfire_string_format(widget->buffer, "%3.0f%%", percentage); - if (r < 0) + if (r) return NULL; return widget->buffer; @@ -526,7 +526,7 @@ static const char* pakfire_progressbar_timer(struct pakfire_progressbar* p, return NULL; int r = pakfire_string_format(widget->buffer, "%02lu:%02lu", t / 60, t % 60); - if (r < 0) + if (r) return NULL; return widget->buffer; @@ -553,14 +553,14 @@ static const char* pakfire_progressbar_eta(struct pakfire_progressbar* p, // Print a placeholder when we haven't started yet if (p->value == 0) { r = pakfire_string_format(widget->buffer, "%-5s: --:--:--", _("ETA")); - if (r < 0) + if (r) return NULL; // Show total time when finished } else if (p->status == PAKFIRE_PROGRESSBAR_FINISHED) { r = pakfire_string_format(widget->buffer, "%-5s: %02lu:%02lu", _("Time"), t / 60, t % 60); - if (r < 0) + if (r) return NULL; // Calculate the ETA @@ -569,7 +569,7 @@ static const char* pakfire_progressbar_eta(struct pakfire_progressbar* p, r = pakfire_string_format(widget->buffer, "%-5s: %02lu:%02lu", _("ETA"), eta / 60, eta % 60); - if (r < 0) + if (r) return NULL; } diff --git a/src/libpakfire/repo.c b/src/libpakfire/repo.c index 138aa5427..d0801a989 100644 --- a/src/libpakfire/repo.c +++ b/src/libpakfire/repo.c @@ -1141,7 +1141,7 @@ static int pakfire_repo_write_database(struct pakfire_repo* repo, const char* pa // Create path for a temporary database export file r = pakfire_string_format(tmp, "%s/repodata/.pakfire-solv.XXXXXX", path); - if (r < 0) + if (r) return r; // Create a temporary file to write to @@ -1171,7 +1171,7 @@ static int pakfire_repo_write_database(struct pakfire_repo* repo, const char* pa // Make final database path r = pakfire_string_format(database, "%s/repodata/%s", path, filename); - if (r < 0) { + if (r) { ERROR(repo->pakfire, "Could not join database path: %m\n"); goto ERROR; } @@ -1274,7 +1274,7 @@ static int pakfire_repo_write_metadata(struct pakfire_repo* repo) { // Make path to repomd.json r = pakfire_string_format(repomd_path, "%s/repodata/repomd.json", path); - if (r < 0) + if (r) goto ERROR; // Open repomd.json for writing @@ -1326,7 +1326,7 @@ PAKFIRE_EXPORT int pakfire_repo_compose(struct pakfire* pakfire, const char* pat // Prefix path with file:// to form baseurl r = pakfire_string_format(baseurl, "file://%s", path); - if (r < 0) + if (r) return 1; // Create a new temporary repository at path diff --git a/src/libpakfire/request.c b/src/libpakfire/request.c index 4642db657..040ce4a72 100644 --- a/src/libpakfire/request.c +++ b/src/libpakfire/request.c @@ -114,7 +114,7 @@ static void pakfire_request_lock_running_kernel(struct pakfire_request* request) DEBUG(request->pakfire, "Locking running kernel %s\n", utsname.release); r = pakfire_string_format(buffer, "kernel(%s)", utsname.release); - if (r < 0) + if (r) return; Pool* pool = pakfire_get_solv_pool(request->pakfire); diff --git a/tests/libpakfire/compress.c b/tests/libpakfire/compress.c index 880f085d3..3504628d1 100644 --- a/tests/libpakfire/compress.c +++ b/tests/libpakfire/compress.c @@ -38,8 +38,7 @@ static int read_test(const struct test* t, char path[PATH_MAX]; char buffer[1024]; - r = pakfire_string_format(path, "%s/%s", TEST_SRC_PATH, file); - ASSERT(r >= 0); + ASSERT_SUCCESS(pakfire_string_format(path, "%s/%s", TEST_SRC_PATH, file)); // Open file ASSERT(f = fopen(path, "r"));