ruby-changes:12334
From: nobu <ko1@a...>
Date: Sat, 11 Jul 2009 02:38:10 +0900 (JST)
Subject: [ruby-changes:12334] Ruby:r24029 (trunk): * random.c (limited_rand): expands to long before shift so that
nobu 2009-07-11 02:37:52 +0900 (Sat, 11 Jul 2009) New Revision: 24029 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=24029 Log: * random.c (limited_rand): expands to long before shift so that the result does not overflow. Modified files: trunk/ChangeLog trunk/random.c Index: ChangeLog =================================================================== --- ChangeLog (revision 24028) +++ ChangeLog (revision 24029) @@ -1,3 +1,8 @@ +Sat Jul 11 02:37:37 2009 Nobuyoshi Nakada <nobu@r...> + + * random.c (limited_rand): expands to long before shift so tha + the result does not overflow. + Sat Jul 11 00:16:27 2009 Nobuyoshi Nakada <nobu@r...> * random.c (rand_init): got rid of buffer overflow. Index: random.c =================================================================== --- random.c (revision 24028) +++ random.c (revision 24029) @@ -414,8 +414,8 @@ retry: val = 0; for (i = SIZEOF_LONG/4-1; 0 <= i; i--) { - if (mask >> (i * 32)) { - val |= genrand_int32(mt) << (i * 32); + if ((mask >> (i * 32)) & 0xffffffff) { + val |= (unsigned long)genrand_int32(mt) << (i * 32); val &= mask; if (limit < val) goto retry; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/