From d2ec14fa4ab944760d3e6740d8ac3ae540dd12a0 Mon Sep 17 00:00:00 2001 From: Explorer09 Date: Mon, 15 Apr 2024 21:48:43 +0800 Subject: Fix GCC build warning in NetBSD 10 The warning message is "array subscript has type 'char' [-Wchar-subscripts]" Fix this by casting to 'unsigned char' before passing any character to a `` function. Also add an assertion to RichString_writeFromAscii() to ensure the characters in the string are all in ASCII range. Signed-off-by: Kang-Che Sung --- RichString.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'RichString.c') diff --git a/RichString.c b/RichString.c index 556674b0..248b3ae0 100644 --- a/RichString.c +++ b/RichString.c @@ -9,7 +9,9 @@ in the source distribution for its full text. #include "RichString.h" +#include #include +#include // IWYU pragma: keep #include #include @@ -144,7 +146,8 @@ static inline int RichString_writeFromAscii(RichString* this, int attrs, const c int newLen = from + len; RichString_setLen(this, newLen); for (int i = from, j = 0; i < newLen; i++, j++) { - this->chptr[i] = (CharType) { .attr = attrs & 0xffffff, .chars = { (isprint(data[j]) ? data[j] : L'\xFFFD') } }; + assert((unsigned char)data[j] <= SCHAR_MAX); + this->chptr[i] = (CharType) { .attr = attrs & 0xffffff, .chars = { (isprint((unsigned char)data[j]) ? data[j] : L'\xFFFD') } }; } return len; -- cgit v1.2.3