From b9a7c6a0adeb60e8811aa9cd121a4d7bd170401e Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sat, 15 Feb 2025 14:47:05 +0000 Subject: [PATCH] Use assert() to make the static analyzer happy Signed-off-by: Michael Tremer --- src/pakfire/archive.c | 6 ++---- src/pakfire/path.c | 16 ++++++---------- src/pakfire/repo.c | 9 +++------ 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/pakfire/archive.c b/src/pakfire/archive.c index 5df266cd..148ba784 100644 --- a/src/pakfire/archive.c +++ b/src/pakfire/archive.c @@ -18,6 +18,7 @@ # # #############################################################################*/ +#include #include #include #include @@ -605,10 +606,7 @@ static int __pakfire_archive_read_metadata(struct pakfire_archive* archive, } // Make the static analyzer happy which thinks this could be NULL - if (!data) { - r = -EINVAL; - goto ERROR; - } + assert(data); // Format >= 6 if (likely(archive->format >= 6)) { diff --git a/src/pakfire/path.c b/src/pakfire/path.c index 0f5a60e7..e0b1985b 100644 --- a/src/pakfire/path.c +++ b/src/pakfire/path.c @@ -18,6 +18,7 @@ # # #############################################################################*/ +#include #include #include #include @@ -402,8 +403,7 @@ int __pakfire_path_basename(char* buffer, const size_t length, const char* s) { goto ERROR; // Make the static analyzer happy - if (!path) - goto ERROR; + assert(path); // Drop everything but the last segment while (path->num_segments > 1) { @@ -441,8 +441,7 @@ int __pakfire_path_dirname(char* buffer, const size_t length, const char* s) { goto ERROR; // Make the static analyzer happy - if (!path) - goto ERROR; + assert(path); // Drop the last segment r = pakfire_path_remove_segment(path, path->num_segments - 1); @@ -477,8 +476,7 @@ int __pakfire_path_relative(char* buffer, const size_t length, const char* __roo goto ERROR; // Make the static analyzer happy - if (!root || !path) - goto ERROR; + assert(root && path); // Both paths must be absolute if (!root->is_absolute || !path->is_absolute) { @@ -535,8 +533,7 @@ int pakfire_path_is_absolute(const char* s) { return r; // Make the static analyzer happy - if (!path) - return -EINVAL; + assert(path); // Is this absolute? r = path->is_absolute; @@ -556,8 +553,7 @@ int __pakfire_path_absolute(char* buffer, const size_t length, const char* s) { return r; // Make the static analyzer happy - if (!path) - return -EINVAL; + assert(path); // Make it absolute path->is_absolute = 1; diff --git a/src/pakfire/repo.c b/src/pakfire/repo.c index b8ff0fda..1e7e2be2 100644 --- a/src/pakfire/repo.c +++ b/src/pakfire/repo.c @@ -18,6 +18,7 @@ # # #############################################################################*/ +#include #include #include #include @@ -361,8 +362,7 @@ static int __pakfire_repo_import(struct pakfire_config* config, const char* sect goto ERROR; // Make the static analyzer happy - if (!self) - goto ERROR; + assert(self); // Enabled pakfire_repo_set_enabled(self, pakfire_config_get_bool(config, section, "enabled", 1)); @@ -1478,10 +1478,7 @@ int pakfire_repo_create(struct pakfire_repo** repo, } // Make the static analyzer happy - if (!self->appdata) { - r = -ENOMEM; - goto ERROR; - } + assert(self->appdata); // Update the subpriority pakfire_repo_update_subpriority(self); -- 2.39.5