diff options
author | Explorer09 <explorer09@gmail.com> | 2024-04-15 21:48:43 +0800 |
---|---|---|
committer | cgzones <cgzones@googlemail.com> | 2024-04-26 19:35:15 +0200 |
commit | d2ec14fa4ab944760d3e6740d8ac3ae540dd12a0 (patch) | |
tree | 67dd84aa2a09805232cd45d4a17bd7a70655b9b1 | |
parent | e54871b6795ac59ee7f98ecfbec50368513d0c6f (diff) |
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
`<ctype.h>` 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 <explorer09@gmail.com>
-rw-r--r-- | RichString.c | 5 | ||||
-rw-r--r-- | Settings.c | 2 |
2 files changed, 5 insertions, 2 deletions
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 <assert.h> #include <ctype.h> +#include <limits.h> // IWYU pragma: keep #include <stdlib.h> #include <string.h> @@ -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; @@ -233,7 +233,7 @@ static const char* toFieldName(Hashtable* columns, int id, bool* enabled) { } static int toFieldIndex(Hashtable* columns, const char* str) { - if (isdigit(str[0])) { + if (isdigit((unsigned char)str[0])) { // This "+1" is for compatibility with the older enum format. int id = atoi(str) + 1; if (toFieldName(columns, id, NULL)) { |