From 51fbe0753b241c3880147a9a89244f16fbffedd7 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 11 May 2020 19:42:44 +0200 Subject: Fix error checking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- common.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/common.h b/common.h index 3d76d23..c54d000 100644 --- a/common.h +++ b/common.h @@ -35,17 +35,17 @@ # define __checked_ptr(X, _FUN) X # define __checked_ssize_t(X, _FUN) X # else -# define DEFINE_CHECKED(TYPE, NAME)\ +# define DEFINE_CHECKED(TYPE, NAME, ERR_IF)\ static inline TYPE\ NAME(TYPE ret, const char *func)\ {\ - if (!ret)\ + if (ERR_IF)\ liberror_set_error_errno(strerror(errno), func, errno);\ return ret;\ } -DEFINE_CHECKED(int, __checked_int) -DEFINE_CHECKED(void *, __checked_ptr) -DEFINE_CHECKED(ssize_t, __checked_ssize_t) +DEFINE_CHECKED(int, __checked_int, ret < 0) +DEFINE_CHECKED(void *, __checked_ptr, !ret) +DEFINE_CHECKED(ssize_t, __checked_ssize_t, ret < 0) # endif # define liberror_snprintf(...) __checked_int(snprintf(__VA_ARGS__), "snprintf") # define liberror_close(FD) __checked_int(close(FD), "close") -- cgit v1.2.3-70-g09d2