summaryrefslogtreecommitdiff
path: root/ext/json/parser
diff options
context:
space:
mode:
authorNobuyoshi Nakada <[email protected]>2025-01-30 12:27:45 +0900
committerNobuyoshi Nakada <[email protected]>2025-01-30 16:56:02 +0900
commitdc3d2a3c2ff20c40b715dd18e1ab52a4b8a7619d (patch)
tree52808fd1bd3f0b13ffed5032ade410cd09511434 /ext/json/parser
parent7f70ef64aff9b22b080690cdf9a725a2acb70f17 (diff)
[ruby/json] 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]))) { | ~~~^~~ ``` https://github.com/ruby/json/commit/4431b362f6
Diffstat (limited to 'ext/json/parser')
-rw-r--r--ext/json/parser/parser.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/ext/json/parser/parser.c b/ext/json/parser/parser.c
index 9cbe2c1d7e..c21a5fda5f 100644
--- a/ext/json/parser/parser.c
+++ b/ext/json/parser/parser.c
@@ -135,7 +135,7 @@ static VALUE rstring_cache_fetch(rvalue_cache *cache, const char *str, const lon
return Qfalse;
}
- if (RB_UNLIKELY(!isalpha(str[0]))) {
+ if (RB_UNLIKELY(!isalpha((unsigned char)str[0]))) {
// Simple heuristic, if the first character isn't a letter,
// we're much less likely to see this string again.
// 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
return Qfalse;
}
- if (RB_UNLIKELY(!isalpha(str[0]))) {
+ if (RB_UNLIKELY(!isalpha((unsigned char)str[0]))) {
// Simple heuristic, if the first character isn't a letter,
// we're much less likely to see this string again.
// We mostly want to cache strings that are likely to be repeated.