summaryrefslogtreecommitdiffstats
path: root/lib/libalpm/trans.c
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-06-14 17:01:08 +0200
committerDan McGee <dan@archlinux.org>2011-06-14 17:01:08 +0200
commitee015f086f3c40390659bbc0129b7c08ffd0ed5f (patch)
treeb2ba33041450fd5c5fb226649b88534fdac60ff1 /lib/libalpm/trans.c
parentbe972767358e6dfbb08686555d8e2c0176a55106 (diff)
downloadpacman-ee015f086f3c40390659bbc0129b7c08ffd0ed5f.tar.gz
pacman-ee015f086f3c40390659bbc0129b7c08ffd0ed5f.tar.xz
Ensure handle is valid and pm_errno is reset when calling into API
We didn't do due diligence before and ensure prior pm_errno values weren't influencing what happened in further ALPM calls. I observed one case of early setup code setting pm_errno to PM_ERR_WRONG_ARGS and that flag persisting the entire time we were calling library code. Add a new CHECK_HANDLE() macro that does two things: 1) ensures the handle variable passed to it is non-NULL and 2) clears any existing pm_errno flag set on the handle. This macro can replace many places we used the ASSERT(handle != NULL, ...) pattern before. Several other other places only need a simple 'set to zero' of the pm_errno field. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/trans.c')
-rw-r--r--lib/libalpm/trans.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c
index a95280c7..f0744937 100644
--- a/lib/libalpm/trans.c
+++ b/lib/libalpm/trans.c
@@ -105,7 +105,7 @@ int SYMEXPORT alpm_trans_init(pmhandle_t *handle, pmtransflag_t flags,
int db_version;
/* Sanity checks */
- ASSERT(handle != NULL, return -1);
+ CHECK_HANDLE(handle, return -1);
ASSERT(handle->trans == NULL, RET_ERR(handle, PM_ERR_TRANS_NOT_NULL, -1));
/* lock db */
@@ -168,7 +168,7 @@ int SYMEXPORT alpm_trans_prepare(pmhandle_t *handle, alpm_list_t **data)
pmtrans_t *trans;
/* Sanity checks */
- ASSERT(handle != NULL, return -1);
+ CHECK_HANDLE(handle, return -1);
ASSERT(data != NULL, RET_ERR(handle, PM_ERR_WRONG_ARGS, -1));
trans = handle->trans;
@@ -212,7 +212,7 @@ int SYMEXPORT alpm_trans_commit(pmhandle_t *handle, alpm_list_t **data)
pmtrans_t *trans;
/* Sanity checks */
- ASSERT(handle != NULL, return -1);
+ CHECK_HANDLE(handle, return -1);
trans = handle->trans;
@@ -251,7 +251,7 @@ int SYMEXPORT alpm_trans_interrupt(pmhandle_t *handle)
pmtrans_t *trans;
/* Sanity checks */
- ASSERT(handle != NULL, return -1);
+ CHECK_HANDLE(handle, return -1);
trans = handle->trans;
ASSERT(trans != NULL, RET_ERR(handle, PM_ERR_TRANS_NULL, -1));
@@ -269,7 +269,7 @@ int SYMEXPORT alpm_trans_release(pmhandle_t *handle)
pmtrans_t *trans;
/* Sanity checks */
- ASSERT(handle != NULL, return -1);
+ CHECK_HANDLE(handle, return -1);
trans = handle->trans;
ASSERT(trans != NULL, RET_ERR(handle, PM_ERR_TRANS_NULL, -1));
@@ -414,7 +414,7 @@ cleanup:
pmtransflag_t SYMEXPORT alpm_trans_get_flags(pmhandle_t *handle)
{
/* Sanity checks */
- ASSERT(handle != NULL, return -1);
+ CHECK_HANDLE(handle, return -1);
ASSERT(handle->trans != NULL, RET_ERR(handle, PM_ERR_TRANS_NULL, -1));
return handle->trans->flags;
@@ -423,7 +423,7 @@ pmtransflag_t SYMEXPORT alpm_trans_get_flags(pmhandle_t *handle)
alpm_list_t SYMEXPORT *alpm_trans_get_add(pmhandle_t *handle)
{
/* Sanity checks */
- ASSERT(handle != NULL, return NULL);
+ CHECK_HANDLE(handle, return NULL);
ASSERT(handle->trans != NULL, RET_ERR(handle, PM_ERR_TRANS_NULL, NULL));
return handle->trans->add;
@@ -432,7 +432,7 @@ alpm_list_t SYMEXPORT *alpm_trans_get_add(pmhandle_t *handle)
alpm_list_t SYMEXPORT *alpm_trans_get_remove(pmhandle_t *handle)
{
/* Sanity checks */
- ASSERT(handle != NULL, return NULL);
+ CHECK_HANDLE(handle, return NULL);
ASSERT(handle->trans != NULL, RET_ERR(handle, PM_ERR_TRANS_NULL, NULL));
return handle->trans->remove;