summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2017-03-29 13:33:46 +0300
committerPanu Matilainen <pmatilai@redhat.com>2017-03-29 13:33:46 +0300
commitb8b5cdb09faa87c25cb71c4c6c3bdd0420e71915 (patch)
tree4aab177a22901a2ce37e8cb1d292b2227a3384a7
parent2652bab3e900c2b6b393a480d34a8c6b772cc113 (diff)
downloadrpm-b8b5cdb09faa87c25cb71c4c6c3bdd0420e71915.tar.gz
Fix error handling in rpmDigestBundleAddID()
Besides the logic being completely wrong to begin with, it wasn't actually handling the failure to allocate a digest at all. Do that, and return values according to documentation.
-rw-r--r--rpmio/digest.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/rpmio/digest.c b/rpmio/digest.c
index 81f9f5e76..1f5e1667b 100644
--- a/rpmio/digest.c
+++ b/rpmio/digest.c
@@ -60,17 +60,20 @@ int rpmDigestBundleAdd(rpmDigestBundle bundle, int algo,
int rpmDigestBundleAddID(rpmDigestBundle bundle, int algo, int id,
rpmDigestFlags flags)
{
- DIGEST_CTX ctx = NULL;
+ int rc = -1;
if (id > 0 && findID(bundle, id) < 0) {
int ix = findID(bundle, 0); /* Find first free slot */
if (ix >= 0) {
bundle->digests[ix] = rpmDigestInit(algo, flags);
- bundle->ids[ix]= id;
- if (ix > bundle->index_max)
- bundle->index_max = ix;
+ if (bundle->digests[ix]) {
+ bundle->ids[ix]= id;
+ if (ix > bundle->index_max)
+ bundle->index_max = ix;
+ rc = 0;
+ }
}
}
- return (ctx != NULL);
+ return rc;
}
int rpmDigestBundleUpdate(rpmDigestBundle bundle, const void *data, size_t len)
{