utility: use size_t index and unsigned char cast in lxw_str_tolower

The loop counter was signed int, which is the wrong type for indexing
into a string.  Change it to size_t.

Also add the required (unsigned char) cast on the tolower argument.
Passing a plain char to tolower is undefined behaviour when char is signed
and the value is negative (any byte with the high bit set).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Bill Denney 2026-04-05 18:36:55 +00:00
parent de6aaee236
commit da95035568

View file

@ -589,10 +589,10 @@ lxw_utf8_strlen(const char *str)
void
lxw_str_tolower(char *str)
{
int i;
size_t i;
for (i = 0; str[i]; i++)
str[i] = tolower(str[i]);
str[i] = tolower((unsigned char) str[i]);
}
/* Simple check for empty strings. */