]> git.ipfire.org Git - pakfire.git/commitdiff
file: Make the static analyzer happy
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 18 Jul 2022 09:40:03 +0000 (09:40 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 18 Jul 2022 09:40:03 +0000 (09:40 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/file.c

index 5edc41fc95af2435a7c6531ecef5ac0bb58c4bc1..89aa0a29264540234a60680bb569a47f06d6ee55 100644 (file)
@@ -169,8 +169,10 @@ static void pakfire_file_free(struct pakfire_file* file) {
        for (unsigned int i = 0; i < MAX_DIGESTS; i++) {
                digest = &file->digests[i];
 
-               if (digest->hexdigest)
+               if (digest->hexdigest) {
                        free(digest->hexdigest);
+                       digest->hexdigest = NULL;
+               }
        }
 
        pakfire_unref(file->pakfire);
@@ -327,7 +329,13 @@ PAKFIRE_EXPORT int pakfire_file_set_digest(struct pakfire_file* file,
                d = pakfire_file_find_digest(file, PAKFIRE_DIGEST_NONE);
 
        // If we could not find a free spot, we probably run out of space
-       if (!d || length > sizeof(d->digest)) {
+       if (!d) {
+               errno = ENOBUFS;
+               return 1;
+       }
+
+       // Check if the digest fits into our pre-allocated buffer space
+       if (length > sizeof(d->digest)) {
                errno = ENOBUFS;
                return 1;
        }