Skip to content

Commit 4431b36

Browse files
committed
Avoid plain char for ctype macros
On some platforms ctype functions are defined as macros accesing tables. A plain char may be `signed` or `unsigned` per implementations and the extension result implementation dependent. gcc warns such case: ``` parser.c: In function 'rstring_cache_fetch': parser.c:138:33: warning: array subscript has type 'char' [-Wchar-subscripts] 138 | if (RB_UNLIKELY(!isalpha(str[0]))) { | ~~~^~~ parser.c: In function 'rsymbol_cache_fetch': parser.c:190:33: warning: array subscript has type 'char' [-Wchar-subscripts] 190 | if (RB_UNLIKELY(!isalpha(str[0]))) { | ~~~^~~ ```
1 parent f3fb8a2 commit 4431b36

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

ext/json/ext/parser/parser.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ static VALUE rstring_cache_fetch(rvalue_cache *cache, const char *str, const lon
135135
return Qfalse;
136136
}
137137

138-
if (RB_UNLIKELY(!isalpha(str[0]))) {
138+
if (RB_UNLIKELY(!isalpha((unsigned char)str[0]))) {
139139
// Simple heuristic, if the first character isn't a letter,
140140
// we're much less likely to see this string again.
141141
// We mostly want to cache strings that are likely to be repeated.
@@ -187,7 +187,7 @@ static VALUE rsymbol_cache_fetch(rvalue_cache *cache, const char *str, const lon
187187
return Qfalse;
188188
}
189189

190-
if (RB_UNLIKELY(!isalpha(str[0]))) {
190+
if (RB_UNLIKELY(!isalpha((unsigned char)str[0]))) {
191191
// Simple heuristic, if the first character isn't a letter,
192192
// we're much less likely to see this string again.
193193
// We mostly want to cache strings that are likely to be repeated.

0 commit comments

Comments
 (0)