From ee015f086f3c40390659bbc0129b7c08ffd0ed5f Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Tue, 14 Jun 2011 10:01:08 -0500 Subject: 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 --- lib/libalpm/trans.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'lib/libalpm/trans.c') 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; -- cgit v1.2.3-24-g4f1b