Skip to content

Commit 75f9a47

Browse files
mamehsbt
authored andcommitted
ext/json/parser/parser.rl: Use "signed" char to contain negative values
char is not always signed. In fact, it is unsigned in arm. https://rubyci.org/logs/rubyci.s3.amazonaws.com/scw-9d6766/ruby-master/log/20191004T181708Z.log.html.gz ``` compiling parser.c parser.rl: In function ‘unescape_unicode’: parser.rl:50:5: warning: comparison is always false due to limited range of data type [-Wtype-limits] if (b < 0) return UNI_REPLACEMENT_CHAR; ^ ```
1 parent 59b29a5 commit 75f9a47

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

ext/json/ext/parser/parser.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ enc_raise(rb_encoding *enc, VALUE exc, const char *fmt, ...)
2727

2828
/* unicode */
2929

30-
static const char digit_values[256] = {
30+
static const signed char digit_values[256] = {
3131
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3232
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3333
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1,
@@ -46,7 +46,7 @@ static const char digit_values[256] = {
4646

4747
static UTF32 unescape_unicode(const unsigned char *p)
4848
{
49-
char b;
49+
signed char b;
5050
UTF32 result = 0;
5151
b = digit_values[p[0]];
5252
if (b < 0) return UNI_REPLACEMENT_CHAR;

ext/json/ext/parser/parser.rl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ enc_raise(rb_encoding *enc, VALUE exc, const char *fmt, ...)
2525

2626
/* unicode */
2727

28-
static const char digit_values[256] = {
28+
static const signed char digit_values[256] = {
2929
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3030
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3131
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1,
@@ -44,7 +44,7 @@ static const char digit_values[256] = {
4444

4545
static UTF32 unescape_unicode(const unsigned char *p)
4646
{
47-
char b;
47+
signed char b;
4848
UTF32 result = 0;
4949
b = digit_values[p[0]];
5050
if (b < 0) return UNI_REPLACEMENT_CHAR;

0 commit comments

Comments
 (0)