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
1 changed files with 3 additions and 3 deletions

View File

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