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
0037b7e5fb
commit
9677750e3d
|
@ -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 New Issue