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:
parent
ca64484e0b
commit
e056fab708
1 changed files with 3 additions and 3 deletions
|
@ -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; \
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue