mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	* random.c (make_seed_value): fix leading-zero-guard condition on
bdigit is smaller than 32bit. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27328 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									5ee43b0a94
								
							
						
					
					
						commit
						5d8c8b46bb
					
				
					 2 changed files with 14 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -1,3 +1,8 @@
 | 
			
		|||
Tue Apr 13 15:00:45 2010  Nobuyoshi Nakada  <nobu@ruby-lang.org>
 | 
			
		||||
 | 
			
		||||
	* random.c (make_seed_value): fix leading-zero-guard condition on
 | 
			
		||||
	  bdigit is smaller than 32bit.
 | 
			
		||||
 | 
			
		||||
Tue Apr 13 13:57:36 2010  Keiju Ishitsuka  <keiju@ruby-lang.org>
 | 
			
		||||
 | 
			
		||||
	* lib/irb/completion.rb (CompletionProc): fix [ruby-dev:40953]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										11
									
								
								random.c
									
										
									
									
									
								
							
							
						
						
									
										11
									
								
								random.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -516,18 +516,25 @@ fill_random_seed(unsigned int seed[DEFAULT_SEED_CNT])
 | 
			
		|||
static VALUE
 | 
			
		||||
make_seed_value(const void *ptr)
 | 
			
		||||
{
 | 
			
		||||
    const long len = DEFAULT_SEED_LEN/SIZEOF_BDIGITS;
 | 
			
		||||
    BDIGIT *digits;
 | 
			
		||||
    NEWOBJ(big, struct RBignum);
 | 
			
		||||
    OBJSETUP(big, rb_cBignum, T_BIGNUM);
 | 
			
		||||
 | 
			
		||||
    RBIGNUM_SET_SIGN(big, 1);
 | 
			
		||||
    rb_big_resize((VALUE)big, DEFAULT_SEED_LEN / SIZEOF_BDIGITS + 1);
 | 
			
		||||
    rb_big_resize((VALUE)big, len + 1);
 | 
			
		||||
    digits = RBIGNUM_DIGITS(big);
 | 
			
		||||
 | 
			
		||||
    MEMCPY(digits, ptr, char, DEFAULT_SEED_LEN);
 | 
			
		||||
 | 
			
		||||
    /* set leading-zero-guard if need. */
 | 
			
		||||
    digits[RBIGNUM_LEN(big)-1] = digits[RBIGNUM_LEN(big)-2] <= 1 ? 1 : 0;
 | 
			
		||||
    digits[len] =
 | 
			
		||||
#if SIZEOF_INT32 / SIZEOF_BDIGITS > 1
 | 
			
		||||
	digits[len-2] <= 1 && digits[len-1] == 0
 | 
			
		||||
#else
 | 
			
		||||
	digits[len-1] <= 1
 | 
			
		||||
#endif
 | 
			
		||||
	? 1 : 0;
 | 
			
		||||
 | 
			
		||||
    return rb_big_norm((VALUE)big);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue