Author: [EMAIL PROTECTED]
Date: Tue Sep  9 23:59:41 2008
New Revision: 246

Modified:
    branches/bleeding_edge/src/platform-linux.cc
    branches/bleeding_edge/src/platform-macos.cc
    branches/bleeding_edge/src/platform-win32.cc

Log:
Fix issue http://code.google.com/p/v8/issues/detail?id=58:
- Prevent a clipping of values when converting a double to an unsigned int
   for use as the random generator's seed value.
Review URL: http://codereview.chromium.org/1887

Modified: branches/bleeding_edge/src/platform-linux.cc
==============================================================================
--- branches/bleeding_edge/src/platform-linux.cc        (original)
+++ branches/bleeding_edge/src/platform-linux.cc        Tue Sep  9 23:59:41 2008
@@ -67,7 +67,12 @@

  void OS::Setup() {
    // Seed the random number generator.
-  srandom(static_cast<unsigned int>(TimeCurrentMillis()));
+  // Convert the current time to a 64-bit integer first, before converting  
it
+  // to an unsigned. Going directly can cause an overflow and the seed to  
be
+  // set to all ones. The seed will be identical for different instances  
that
+  // call this setup code within the same millisecond.
+  uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis());
+  srandom(static_cast<unsigned int>(seed));
  }



Modified: branches/bleeding_edge/src/platform-macos.cc
==============================================================================
--- branches/bleeding_edge/src/platform-macos.cc        (original)
+++ branches/bleeding_edge/src/platform-macos.cc        Tue Sep  9 23:59:41 2008
@@ -73,7 +73,12 @@

  void OS::Setup() {
    // Seed the random number generator.
-  srandom(static_cast<unsigned int>(TimeCurrentMillis()));
+  // Convert the current time to a 64-bit integer first, before converting  
it
+  // to an unsigned. Going directly will cause an overflow and the seed to  
be
+  // set to all ones. The seed will be identical for different instances  
that
+  // call this setup code within the same millisecond.
+  uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis());
+  srandom(static_cast<unsigned int>(seed));
  }



Modified: branches/bleeding_edge/src/platform-win32.cc
==============================================================================
--- branches/bleeding_edge/src/platform-win32.cc        (original)
+++ branches/bleeding_edge/src/platform-win32.cc        Tue Sep  9 23:59:41 2008
@@ -493,7 +493,12 @@

  void OS::Setup() {
    // Seed the random number generator.
-  srand(static_cast<unsigned int>(TimeCurrentMillis()));
+  // Convert the current time to a 64-bit integer first, before converting  
it
+  // to an unsigned. Going directly can cause an overflow and the seed to  
be
+  // set to all ones. The seed will be identical for different instances  
that
+  // call this setup code within the same millisecond.
+  uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis());
+  srand(static_cast<unsigned int>(seed));
  }



--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to