Project

General

Profile

Bug #10453 ยป num2chr-range-check-10453.patch

jeremyevans0 (Jeremy Evans), 08/12/2019 02:38 AM

View differences:

include/ruby/ruby.h
1626 1626
}
1627 1627
#define RB_ULONG2NUM(x) rb_ulong2num_inline(x)
1628 1628

  
1629
static inline char
1630
rb_num2char_inline(VALUE x)
1631
{
1632
    if (RB_TYPE_P(x, RUBY_T_STRING) && (RSTRING_LEN(x)>=1))
1633
	return RSTRING_PTR(x)[0];
1634
    else
1635
	return (char)(NUM2INT(x) & 0xff);
1636
}
1637 1629
#define RB_NUM2CHR(x) rb_num2char_inline(x)
1638 1630

  
1639 1631
#define RB_CHR2FIX(x) RB_INT2FIX((long)((x)&0xff))
......
2074 2066

  
2075 2067
RUBY_EXTERN VALUE rb_stdin, rb_stdout, rb_stderr;
2076 2068

  
2069
static inline char
2070
rb_num2char_inline(VALUE x)
2071
{
2072
    if (RB_TYPE_P(x, RUBY_T_STRING) && (RSTRING_LEN(x)>=1))
2073
	return RSTRING_PTR(x)[0];
2074
    else {
2075
        unsigned int y = NUM2UINT(x);
2076
        if (y > 0xff)
2077
            rb_raise(rb_eRangeError, "value to large to convert to char: %u", y);
2078
	return (char)(y & 0xff);
2079
    }
2080
}
2081

  
2077 2082
static inline VALUE
2078 2083
rb_class_of(VALUE obj)
2079 2084
{