The current implementation of strncasecmp appears to be calling tolower with values outside of the unsigned char range, which is UB and (in the toolchain implementation) returns values which are unsuitable for 24-bit integer comparison. In the TI-OS implementation of tolower, it effectively treats the input as unsigned char , which possibly hid this issue in strncasecmp. However, that means the TI-OS implementation is not standard-compliant because it doesn't return EOF when given EOF as input.
In short, we can probably ditch the TI-OS implementations of tolower/toupper, and possibly provide an internal ASM entrypoint in our own tolower to make the strncasecmp implementation much more efficient and clean (and more importantly, correct).
Edit: Thanks to @envenomator for reporting this bug on Discord.
The current implementation of
strncasecmp
appears to be callingtolower
with values outside of theunsigned char
range, which is UB and (in the toolchain implementation) returns values which are unsuitable for 24-bit integer comparison. In the TI-OS implementation oftolower
, it effectively treats the input asunsigned char
, which possibly hid this issue instrncasecmp
. However, that means the TI-OS implementation is not standard-compliant because it doesn't return EOF when given EOF as input.In short, we can probably ditch the TI-OS implementations of
tolower
/toupper
, and possibly provide an internal ASM entrypoint in our owntolower
to make thestrncasecmp
implementation much more efficient and clean (and more importantly, correct).Edit: Thanks to @envenomator for reporting this bug on Discord.