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/util.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/libalpm/util.h') diff --git a/lib/libalpm/util.h b/lib/libalpm/util.h index e5fefe9e..0549c81e 100644 --- a/lib/libalpm/util.h +++ b/lib/libalpm/util.h @@ -71,6 +71,8 @@ #define DOUBLE_EQ(x, y) (fabs((x) - (y)) < DBL_EPSILON) +#define CHECK_HANDLE(handle, action) do { if(!(handle)) { action; } (handle)->pm_errno = 0; } while(0) + /** * Used as a buffer/state holder for _alpm_archive_fgets(). */ -- cgit v1.2.3-24-g4f1b