flash/nor/fm4: Fix build on MSYS2 with Clang

The to{upper,lower} macros on MSYS2 (native) and Cygwin are implemented
as table lookups and expect values representable as 'unsigned char'.
Passing a signed char can lead to negative array indices and compile-time
errors (-Werror=char-subscripts).

Add explicit casts to 'unsigned char' to all affected is* calls, as
recommended by the TOUPPER(3) manual page.

Checkpatch-ignore: COMMIT_LOG_LONG_LINE

../src/flash/nor/fm4.c:608:28: error: array subscript is of type 'char' [-Werror,-Wchar-subscripts]
  608 |                 if (pattern[i] != 'x' && tolower(s[i]) != tolower(pattern[i]))
      |                                          ^~~~~~~~~~~~~
/usr/include/ctype.h:172:25: note: expanded from macro 'tolower'
  172 |       (void) __CTYPE_PTR[__x]; (tolower) (__x);})
      |                         ^~~~
../src/flash/nor/fm4.c:608:45: error: array subscript is of type 'char' [-Werror,-Wchar-subscripts]
  608 |                 if (pattern[i] != 'x' && tolower(s[i]) != tolower(pattern[i]))
      |                                                           ^~~~~~~~~~~~~~~~~~~
/usr/include/ctype.h:172:25: note: expanded from macro 'tolower'
  172 |       (void) __CTYPE_PTR[__x]; (tolower) (__x);})
      |                         ^~~~

Change-Id: If9cca0a252d091bf01774ad33224904d807ee16c
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: https://review.openocd.org/c/openocd/+/9539
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
This commit is contained in:
Marc Schink
2026-03-13 13:14:18 +01:00
committed by Antonio Borneo
parent 232cd0b0f1
commit 3d83e9546e

View File

@@ -605,7 +605,7 @@ static bool fm4_name_match(const char *s, const char *pattern)
if (!pattern[i])
return true;
/* Use x as wildcard */
if (pattern[i] != 'x' && tolower(s[i]) != tolower(pattern[i]))
if (pattern[i] != 'x' && tolower((unsigned char)s[i]) != tolower((unsigned char)pattern[i]))
return false;
i++;
}