From 3d83e9546e1f5050a7079eeca0a18d4259cd4949 Mon Sep 17 00:00:00 2001 From: Marc Schink Date: Fri, 13 Mar 2026 13:14:18 +0100 Subject: [PATCH] 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 Reviewed-on: https://review.openocd.org/c/openocd/+/9539 Tested-by: jenkins Reviewed-by: Antonio Borneo --- src/flash/nor/fm4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flash/nor/fm4.c b/src/flash/nor/fm4.c index 2db79ef50..4c8f14c9a 100644 --- a/src/flash/nor/fm4.c +++ b/src/flash/nor/fm4.c @@ -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++; }