From: Michael Tremer Date: Tue, 22 Oct 2024 15:37:07 +0000 (+0000) Subject: path: Make the static analyzer happy X-Git-Tag: 0.9.30~948 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=847894d6858fbbb4a137022538741c2f355e6cbf;p=pakfire.git path: Make the static analyzer happy I don't see how path can be NULL here, but let's rather be safe and check for it. Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/path.c b/src/libpakfire/path.c index a0262ebde..e18bf8d96 100644 --- a/src/libpakfire/path.c +++ b/src/libpakfire/path.c @@ -38,7 +38,6 @@ struct pakfire_path { static void pakfire_path_free_segments(struct pakfire_path* path) { for (unsigned int i = 0; i < path->num_segments; i++) free(path->segments[i]); - free(path->segments); // Reset the data structure @@ -128,7 +127,7 @@ static int pakfire_path_import_segments(struct pakfire_path* path, const char* s // Copy path into buffer r = pakfire_string_set(buffer, s); - if (r) + if (r < 0) return r; const char* segment = strtok_r(buffer, "/", &p); @@ -136,7 +135,7 @@ static int pakfire_path_import_segments(struct pakfire_path* path, const char* s // Append all segments while (segment) { r = pakfire_path_append_segment(path, segment); - if (r) + if (r < 0) break; segment = strtok_r(NULL, "/", &p); @@ -160,11 +159,12 @@ static int pakfire_path_parse(struct pakfire_path** path, const char* s) { // Import the path r = pakfire_path_import_segments(p, s); - if (r) + if (r < 0) goto ERROR; // Success *path = p; + return 0; ERROR: @@ -222,6 +222,10 @@ static int pakfire_path_to_string(struct pakfire_path* path, char* buffer, const static int pakfire_path_do_normalize(struct pakfire_path* path) { int r; + // Make the analyzer happy + if (!path) + return -EINVAL; + for (unsigned int i = 0; i < path->num_segments; i++) { // Simply remove single dots if (strcmp(path->segments[i], ".") == 0) { @@ -375,7 +379,11 @@ int __pakfire_path_basename(char* buffer, const size_t length, const char* s) { // Parse the path r = pakfire_path_parse(&path, s); - if (r) + if (r < 0) + goto ERROR; + + // Make the static analyzer happy + if (!path) goto ERROR; // Drop everything but the last segment @@ -413,6 +421,10 @@ int __pakfire_path_dirname(char* buffer, const size_t length, const char* s) { if (r) goto ERROR; + // Make the static analyzer happy + if (!path) + goto ERROR; + // Drop the last segment r = pakfire_path_remove_segment(path, path->num_segments - 1); if (r) @@ -445,6 +457,10 @@ int __pakfire_path_relative(char* buffer, const size_t length, const char* __roo if (r) goto ERROR; + // Make the static analyzer happy + if (!root || !path) + goto ERROR; + // Both paths must be absolute if (!root->is_absolute || !path->is_absolute) { r = -EINVAL;