From cb50b53467d4677e586247b5c2774bd5c4bbb1b6 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 7 Sep 2015 10:34:15 +1000 Subject: [PATCH] Don't allow for more than INT_MAX refs on each struct "2^31 are enough for anyone" Signed-off-by: Peter Hutterer --- src/libratbag.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/libratbag.c b/src/libratbag.c index d7dbd35a..71f02732 100644 --- a/src/libratbag.c +++ b/src/libratbag.c @@ -33,6 +33,7 @@ #include #include #include +#include #include "libratbag-private.h" #include "libratbag-util.h" @@ -531,6 +532,8 @@ out_err: LIBRATBAG_EXPORT struct ratbag_device * ratbag_device_ref(struct ratbag_device *device) { + assert(device->refcount < INT_MAX); + device->refcount++; return device; } @@ -714,6 +717,8 @@ ratbag_device_init_profiles(struct ratbag_device *device, LIBRATBAG_EXPORT struct ratbag_profile * ratbag_profile_ref(struct ratbag_profile *profile) { + assert(profile->refcount < INT_MAX); + ratbag_device_ref(profile->device); profile->refcount++; return profile; @@ -899,6 +904,8 @@ ratbag_profile_get_resolution(struct ratbag_profile *profile, unsigned int idx) LIBRATBAG_EXPORT struct ratbag_resolution * ratbag_resolution_ref(struct ratbag_resolution *resolution) { + assert(resolution->refcount < INT_MAX); + ratbag_profile_ref(resolution->profile); resolution->refcount++; return resolution; @@ -1187,6 +1194,8 @@ ratbag_button_disable(struct ratbag_button *button) LIBRATBAG_EXPORT struct ratbag_button * ratbag_button_ref(struct ratbag_button *button) { + assert(button->refcount < INT_MAX); + ratbag_profile_ref(button->profile); button->refcount++; return button;