summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2025-12-31 21:40:16 +0900
committergit <svn-admin@ruby-lang.org>2025-12-31 12:44:18 +0000
commit99249cc582177f05baf2a9c45e3fa21b891c70e9 (patch)
treee8abe2fe580a3d47916055c1af1c4bcb77a1e7ee /ext
parentc97f5d591b17b8194b8ddfccc6fb9d94b66c6bce (diff)
[ruby/json] Fix non-portable code
A plain `char` may be `signed` or `unsigned` depending on the implementation. Also, bitwise ORing of `signed` values ​​is not guaranteed to be `signed`. To ensure portability, should logical-OR each comparison, but casting to `signed char` is usually sufficient. https://github.com/ruby/json/commit/8ad744c532
Diffstat (limited to 'ext')
-rw-r--r--ext/json/parser/parser.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/ext/json/parser/parser.c b/ext/json/parser/parser.c
index 60ed689fde..0ac16918f8 100644
--- a/ext/json/parser/parser.c
+++ b/ext/json/parser/parser.c
@@ -485,12 +485,12 @@ static uint32_t unescape_unicode(JSON_ParserState *state, const char *sp, const
const unsigned char *p = (const unsigned char *)sp;
- const char b0 = digit_values[p[0]];
- const char b1 = digit_values[p[1]];
- const char b2 = digit_values[p[2]];
- const char b3 = digit_values[p[3]];
+ const signed char b0 = digit_values[p[0]];
+ const signed char b1 = digit_values[p[1]];
+ const signed char b2 = digit_values[p[2]];
+ const signed char b3 = digit_values[p[3]];
- if (RB_UNLIKELY((b0 | b1 | b2 | b3) < 0)) {
+ if (RB_UNLIKELY((signed char)(b0 | b1 | b2 | b3) < 0)) {
raise_parse_error_at("incomplete unicode character escape sequence at %s", state, sp - 2);
}