[mono/mono] [2 commits] edbcf074: fix DivideByZeroException in Random.Next()
| Newsgroups | gmane.comp.gnome.mono.patches |
|---|---|
| Message-ID | <00000141e7474acc-93459073-326b-4ad9-87ff-28a7e21573df-000000@email.amazonses.com> |
Branch: refs/heads/master
Home: https://github.com/mono/mono
Compare: https://github.com/mono/mono/compare/caff05560933...c0cbbb15d9de
Commit: edbcf074ce6cb21301a1a43d72f5c5b44694ac84
Author: xplicit <[email protected]> (xplicit)
Date: 2013-10-23 21:09:30 GMT
URL: https://github.com/mono/mono/commit/edbcf074ce6cb21301a1a43d72f5c5b44694ac84
fix DivideByZeroException in Random.Next()
Changed paths:
M mcs/class/corlib/System/Random.cs
M mcs/class/corlib/Test/System/RandomTest.cs
Modified: mcs/class/corlib/System/Random.cs
===================================================================
@@ -87,7 +87,7 @@ public virtual int Next (int maxValue)
if (maxValue < 0)
throw new ArgumentOutOfRangeException ("Maximum value is less than minimal value.");
- return (int) (JKiss () % maxValue);
+ return maxValue > 0 ? (int)(JKiss () % maxValue) : 0;
}
public virtual int Next ()
Modified: mcs/class/corlib/Test/System/RandomTest.cs
===================================================================
@@ -58,6 +58,13 @@ public void Next ()
}
[Test]
+ public void NextZero ()
+ {
+ Random r = new Random ();
+ Assert.AreEqual (0, r.Next (0),"Next(0) failed");
+ }
+
+ [Test]
public void NextMax()
{
Random r = new Random();
Commit: c0cbbb15d9dea9d4599e1b8a235961295050dfaf
Author: Sebastien Pouliot <[email protected]> (spouliot)
Date: 2013-10-23 21:42:48 GMT
URL: https://github.com/mono/mono/commit/c0cbbb15d9dea9d4599e1b8a235961295050dfaf
Merge pull request #786 from xplicit/master
fix DivideByZeroException in Random.Next()
Changed paths:
M mcs/class/corlib/System/Random.cs
M mcs/class/corlib/Test/System/RandomTest.cs
Modified: mcs/class/corlib/System/Random.cs
===================================================================
@@ -87,7 +87,7 @@ public virtual int Next (int maxValue)
if (maxValue < 0)
throw new ArgumentOutOfRangeException ("Maximum value is less than minimal value.");
- return (int) (JKiss () % maxValue);
+ return maxValue > 0 ? (int)(JKiss () % maxValue) : 0;
}
public virtual int Next ()
Modified: mcs/class/corlib/Test/System/RandomTest.cs
===================================================================
@@ -58,6 +58,13 @@ public void Next ()
}
[Test]
+ public void NextZero ()
+ {
+ Random r = new Random ();
+ Assert.AreEqual (0, r.Next (0),"Next(0) failed");
+ }
+
+ [Test]
public void NextMax()
{
Random r = new Random();
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches