Skip to content

Commit d2ec14f

Browse files
Explorer09cgzones
authored andcommitted
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>
1 parent e54871b commit d2ec14f

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

RichString.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ in the source distribution for its full text.
99

1010
#include "RichString.h"
1111

12+
#include <assert.h>
1213
#include <ctype.h>
14+
#include <limits.h> // IWYU pragma: keep
1315
#include <stdlib.h>
1416
#include <string.h>
1517

@@ -144,7 +146,8 @@ static inline int RichString_writeFromAscii(RichString* this, int attrs, const c
144146
int newLen = from + len;
145147
RichString_setLen(this, newLen);
146148
for (int i = from, j = 0; i < newLen; i++, j++) {
147-
this->chptr[i] = (CharType) { .attr = attrs & 0xffffff, .chars = { (isprint(data[j]) ? data[j] : L'\xFFFD') } };
149+
assert((unsigned char)data[j] <= SCHAR_MAX);
150+
this->chptr[i] = (CharType) { .attr = attrs & 0xffffff, .chars = { (isprint((unsigned char)data[j]) ? data[j] : L'\xFFFD') } };
148151
}
149152

150153
return len;

Settings.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ static const char* toFieldName(Hashtable* columns, int id, bool* enabled) {
233233
}
234234

235235
static int toFieldIndex(Hashtable* columns, const char* str) {
236-
if (isdigit(str[0])) {
236+
if (isdigit((unsigned char)str[0])) {
237237
// This "+1" is for compatibility with the older enum format.
238238
int id = atoi(str) + 1;
239239
if (toFieldName(columns, id, NULL)) {

0 commit comments

Comments
 (0)