From: Adam Saponara Date: Mon, 7 Feb 2022 21:40:44 +0000 (-0500) Subject: Prevent underflow in `memcached_*_response_decrement` macros X-Git-Tag: 1.1.3~1^2 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=c8c52cf24f50f55454ba36250fd54b848d6d9ce2;p=awesomized%2Flibmemcached Prevent underflow in `memcached_*_response_decrement` macros --- diff --git a/src/libmemcached/common.h b/src/libmemcached/common.h index 954353ac..ed12d617 100644 --- a/src/libmemcached/common.h +++ b/src/libmemcached/common.h @@ -140,11 +140,21 @@ static inline void memcached_server_response_increment(memcached_instance_st *in } #endif -#define memcached_server_response_decrement(A) (A)->cursor_active_-- -#define memcached_server_response_reset(A) (A)->cursor_active_ = 0 +#define memcached_server_response_decrement(A) do { \ + WATCHPOINT_ASSERT((A)->cursor_active_ > 0); \ + if ((A)->cursor_active_ > 0) { \ + (A)->cursor_active_--; \ + } \ +} while (0) +#define memcached_server_response_reset(A) (A)->cursor_active_ = 0 #define memcached_instance_response_increment(A) (A)->cursor_active_++ -#define memcached_instance_response_decrement(A) (A)->cursor_active_-- +#define memcached_instance_response_decrement(A) do { \ + WATCHPOINT_ASSERT((A)->cursor_active_ > 0); \ + if ((A)->cursor_active_ > 0) { \ + (A)->cursor_active_--; \ + } \ +} while (0) #define memcached_instance_response_reset(A) (A)->cursor_active_ = 0 #ifdef __cplusplus