Project

General

Profile

Bug #10453

Updated by nobu (Nobuyoshi Nakada) about 10 years ago

`NUM2CHR()` just calls `rb_num2int_inline()` and masks off the high bytes. Consequently, passing any value larger than a `char` and no bigger than an `int` will return some garbage value (rather than raising `RangeError`). 

 To reproduce, compile and run: 

 ~~~C 
 

     #include <ruby.h> 
 
     #include <limits.h> 

 
    
     int main(int argc, char* argv[]) 
 
     { 
     
    	 ruby_init(); 
    
     
    
    	 VALUE y = INT2FIX(INT_MAX); 
     
    	 char z = NUM2CHR(y); 
    
     
    
    	 printf("%hhd\n", z); 
    
     
    
    	 return ruby_cleanup(0); 
 
     } 
 ~~~ 

 Expected: 
 Segfault from uncaught `RangeError`. 

 Actual: 
 Prints -1

Back