This patch is submitted when I was looking at the llvm fsanitize bug on FreeBSD.
At that moment, I was checking if there are some error in libc that may cause this error and discover that some _ctype function are called as macro and thus is without bound_checking.
Take the following function as an exmaple:
#define isprint(c) __sbistype((c), _CTYPE_R)
And it will finally call
static __inline int __maskrune(__ct_rune_t _c, unsigned long _f) { return ((_c < 0 || _c >= _CACHED_RUNES) ? ___runetype(_c) : _CurrentRuneLocale->__runetype[_c]) & _f; }
In this case, The _ct_rune_t type is integer type and the length of __runetype is only 256.
Thus I make a bitmask as a boundary checking on the function which may have this issue.