CE-Programming / toolchain

Toolchain and libraries for C/C++ programming on the TI-84+ CE calculator series
https://ce-programming.github.io/toolchain/index.html
GNU Lesser General Public License v3.0
527 stars 53 forks source link

Incorrect behavior in strncasecmp and TI-OS implementations of tolower/toupper #479

Closed calc84maniac closed 8 months ago

calc84maniac commented 9 months ago

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.