]> git.ipfire.org Git - telemetry.git/commitdiff
file: Another attempt to make the static analyzer happy
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 8 Oct 2025 20:39:06 +0000 (20:39 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 8 Oct 2025 20:39:06 +0000 (20:39 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/daemon/file.c

index b48ddd6a995465570ad171da2fade11aeb8efd6f..870175002982c6c35718b32a20d2aa7560991e85 100644 (file)
@@ -18,6 +18,7 @@
 #                                                                             #
 #############################################################################*/
 
+#include <assert.h>
 #include <errno.h>
 #include <stdint.h>
 #include <stdio.h>
@@ -64,50 +65,62 @@ static int collecty_file_create(collecty_file** file, collecty_ctx* ctx) {
 }
 
 int collecty_file_open_path(collecty_file** file, collecty_ctx* ctx, const char* path) {
+       collecty_file* self = NULL;
        int r;
 
        // Create a new object
-       r = collecty_file_create(file, ctx);
+       r = collecty_file_create(&self, ctx);
        if (r < 0)
                goto ERROR;
 
+       // Make the static analyzer happy
+       assert(self);
+
        // Open the file
-       (*file)->f = fopen(path, "r");
-       if (!(*file)->f) {
+       self->f = fopen(path, "r");
+       if (!self->f) {
                ERROR(ctx, "Failed to open %s: %m\n", path);
                r = -errno;
                goto ERROR;
        }
 
+       // Return the pointer
+       *file = self;
        return 0;
 
 ERROR:
-       if (*file)
-               collecty_file_unref(*file);
+       if (self)
+               collecty_file_unref(self);
 
        return r;
 }
 
 int collecty_file_open_buffer(collecty_file** file, collecty_ctx* ctx, collecty_buffer* buffer) {
+       collecty_file* self = NULL;
        int r;
 
        // Create a new object
-       r = collecty_file_create(file, ctx);
+       r = collecty_file_create(&self, ctx);
        if (r < 0)
                goto ERROR;
 
+       // Make the static analyzer happy
+       assert(self);
+
        // Open the buffer as a file
-       (*file)->f = collecty_buffer_fopen(buffer, "r");
-       if (!(*file)->f) {
+       self->f = collecty_buffer_fopen(buffer, "r");
+       if (!self->f) {
                r = -errno;
                goto ERROR;
        }
 
+       // Return the pointer
+       *file = self;
        return 0;
 
 ERROR:
-       if (*file)
-               collecty_file_unref(*file);
+       if (self)
+               collecty_file_unref(self);
 
        return r;
 }