[Mono-bugs] [Bug 605797] New: Chance to get OverflowException in Random..ctor()

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Thu May 13 20:13:47 EDT 2010


http://bugzilla.novell.com/show_bug.cgi?id=605797

http://bugzilla.novell.com/show_bug.cgi?id=605797#c0


           Summary: Chance to get OverflowException in Random..ctor()
    Classification: Mono
           Product: Mono: Class Libraries
           Version: SVN
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: CORLIB
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: casteg at mail.ru
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---


User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.2.3)
Gecko/20100401 Firefox/3.6.3

Random's default constructor is defined as such:

"public Random () : this (Environment.TickCount) { }"

In Random..ctor(int) we have this line:

"public Random(int Seed)
{
// ...
mj = MSEED - Math.Abs (Seed);"

msdn states the following about Environment.TickCount (sorry, I failed to find
the implementation of get_TickCount, so I assume that mono follows this
specification (or at least it may follow in the future)):

"if the system runs continuously, TickCount  will increment from zero to
Int32.MaxValue for approximately 24.9 days, then jump to Int32.MinValue, which
is a negative number, then increment back to zero during the next 24.9 days."

-- however, Math.Abs is defined to throw OverflowException on Int32.MinValue.
So, there is a (very) small possibility for long-running apps to get random
OverflowExceptions in Random's constructor.

This issue has been fixed in MS .Net 4.0:

(using reflector)
"int num4 = (Seed == -2147483648) ? 0x7fffffff : Math.Abs(Seed);"

where -2147483648 corresponds to Int32.MinValue.

Reproducible: Always

-- 
Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list