Fix ctype style char macros with signed inputs

UTF8 byte codes are commonly stored in signed char types thus these macros could be called with negative numbers. Avoid invalid memory access by clamping the input values to 0 ~ 255 with an unsigned char cast.
This commit is contained in:
Bernhard Schelling 2020-11-19 23:42:05 +09:00 committed by GitHub
parent fbd04ea76e
commit c594e8801d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -44,20 +44,20 @@ RETRO_BEGIN_DECLS
#define string_is_not_equal_fast(a, b, size) (memcmp(a, b, size) != 0) #define string_is_not_equal_fast(a, b, size) (memcmp(a, b, size) != 0)
#define string_is_equal_fast(a, b, size) (memcmp(a, b, size) == 0) #define string_is_equal_fast(a, b, size) (memcmp(a, b, size) == 0)
#define TOLOWER(c) (c | (lr_char_props[c] & 0x20)) #define TOLOWER(c) ((c) | (lr_char_props[(unsigned char)(c)] & 0x20))
#define TOUPPER(c) (c & ~(lr_char_props[c] & 0x20)) #define TOUPPER(c) ((c) & ~(lr_char_props[(unsigned char)(c)] & 0x20))
/* C standard says \f \v are space, but this one disagrees */ /* C standard says \f \v are space, but this one disagrees */
#define ISSPACE(c) (lr_char_props[c] & 0x80) #define ISSPACE(c) (lr_char_props[(unsigned char)(c)] & 0x80)
#define ISDIGIT(c) (lr_char_props[c] & 0x40) #define ISDIGIT(c) (lr_char_props[(unsigned char)(c)] & 0x40)
#define ISALPHA(c) (lr_char_props[c] & 0x20) #define ISALPHA(c) (lr_char_props[(unsigned char)(c)] & 0x20)
#define ISLOWER(c) (lr_char_props[c] & 0x04) #define ISLOWER(c) (lr_char_props[(unsigned char)(c)] & 0x04)
#define ISUPPER(c) (lr_char_props[c] & 0x02) #define ISUPPER(c) (lr_char_props[(unsigned char)(c)] & 0x02)
#define ISALNUM(c) (lr_char_props[c] & 0x60) #define ISALNUM(c) (lr_char_props[(unsigned char)(c)] & 0x60)
#define ISUALPHA(c) (lr_char_props[c] & 0x28) #define ISUALPHA(c) (lr_char_props[(unsigned char)(c)] & 0x28)
#define ISUALNUM(c) (lr_char_props[c] & 0x68) #define ISUALNUM(c) (lr_char_props[(unsigned char)(c)] & 0x68)
#define IS_XDIGIT(c) (lr_char_props[c] & 0x01) #define IS_XDIGIT(c) (lr_char_props[(unsigned char)(c)] & 0x01)
/* Deprecated alias, all callers should use string_is_equal_case_insensitive instead */ /* Deprecated alias, all callers should use string_is_equal_case_insensitive instead */
#define string_is_equal_noncase string_is_equal_case_insensitive #define string_is_equal_noncase string_is_equal_case_insensitive