From: Michael Tremer Date: Mon, 18 Jul 2022 09:40:03 +0000 (+0000) Subject: file: Make the static analyzer happy X-Git-Tag: 0.9.28~682 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=baf8b0edbcdde076cb6e1c45f6258602a2126e10;p=pakfire.git file: Make the static analyzer happy Signed-off-by: Michael Tremer --- 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; }