summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorUli Schlachter <psychon@znc.in>2015-03-18 22:00:27 +0100
committerUli Schlachter <psychon@znc.in>2015-03-18 22:00:27 +0100
commitc851709f018f0cc5a904f7e9ef830fa246322019 (patch)
tree1212c123167cba99914bf11d51e4d6cc6453e326 /src
parent6d842936999b3f31f452b598347cd8f402c5f87d (diff)
Add and use helper macro for range checks
Signed-off-by: Uli Schlachter <psychon@znc.in>
Diffstat (limited to 'src')
-rw-r--r--src/xcb_errors.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/xcb_errors.c b/src/xcb_errors.c
index bea940d..a59a527 100644
--- a/src/xcb_errors.c
+++ b/src/xcb_errors.c
@@ -28,6 +28,8 @@
#include <stdlib.h>
#include <string.h>
+#define IS_IN_RANGE(value, begin, length) ((value) >= (begin) && (value) < (begin) + (length))
+
struct extension_info_t {
struct extension_info_t *next;
struct static_extension_info_t static_info;
@@ -177,8 +179,7 @@ const char *xcb_errors_get_name_for_event(xcb_errors_context_t *ctx,
if (result)
return result;
- while (info && (info->first_event > event_code
- || info->first_event + info->static_info.num_events <= event_code))
+ while (info && !IS_IN_RANGE(event_code, info->first_event, info->static_info.num_events))
info = info->next;
if (info == NULL)
@@ -195,8 +196,7 @@ const char *xcb_errors_get_name_for_error(xcb_errors_context_t *ctx,
if (result)
return result;
- while (info && (info->first_error > error_code
- || info->first_error + info->static_info.num_errors <= error_code))
+ while (info && !IS_IN_RANGE(error_code, info->first_error, info->static_info.num_errors))
info = info->next;
if (info == NULL)