From baf8b0edbcdde076cb6e1c45f6258602a2126e10 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Mon, 18 Jul 2022 09:40:03 +0000 Subject: [PATCH] file: Make the static analyzer happy Signed-off-by: Michael Tremer --- src/libpakfire/file.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/libpakfire/file.c b/src/libpakfire/file.c index 5edc41fc9..89aa0a292 100644 --- a/src/libpakfire/file.c +++ b/src/libpakfire/file.c @@ -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; } -- 2.47.3