1
0
Fork 0
mirror of https://github.com/yshui/picom.git synced 2024-11-11 13:51:02 -05:00

Improve checked cast macros

to_{int,char,i16}_checked now works with unsigned types (except
uint64_t).

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2019-03-30 10:16:15 +00:00
parent ca64484e0b
commit e056fab708
No known key found for this signature in database
GPG key ID: 37C999F617EA1A47

View file

@ -54,14 +54,14 @@ safe_isnan(double a) {
#define to_int_checked(val) \ #define to_int_checked(val) \
({ \ ({ \
auto tmp = (val); \ int64_t tmp = (val); \
assert(tmp >= INT_MIN && tmp <= INT_MAX); \ assert(tmp >= INT_MIN && tmp <= INT_MAX); \
(int)tmp; \ (int)tmp; \
}) })
#define to_char_checked(val) \ #define to_char_checked(val) \
({ \ ({ \
auto tmp = (val); \ int64_t tmp = (val); \
assert(tmp >= CHAR_MIN && tmp <= CHAR_MAX); \ assert(tmp >= CHAR_MIN && tmp <= CHAR_MAX); \
(char)tmp; \ (char)tmp; \
}) })
@ -75,7 +75,7 @@ safe_isnan(double a) {
#define to_i16_checked(val) \ #define to_i16_checked(val) \
({ \ ({ \
auto tmp = (val); \ int64_t tmp = (val); \
assert(tmp >= INT16_MIN && tmp <= INT16_MAX); \ assert(tmp >= INT16_MIN && tmp <= INT16_MAX); \
(int16_t) tmp; \ (int16_t) tmp; \
}) })