Commit fa000133 authored by Brickner_cp's avatar Brickner_cp

Cast from UInt128 to ulong no longer throws an overflow exception if the value is too big.

parent 263d9dbc
...@@ -89,22 +89,21 @@ namespace PcapDotNet.Base.Test ...@@ -89,22 +89,21 @@ namespace PcapDotNet.Base.Test
} }
[TestMethod] [TestMethod]
[ExpectedException(typeof(OverflowException), AllowDerivedTypes = false)]
public void CastToULongOverflow() public void CastToULongOverflow()
{ {
Random random = new Random(); Random random = new Random();
UInt128 value; UInt128 value;
ulong overflow = random.NextULong(ulong.MaxValue);
try try
{ {
value = (UInt128)(((BigInteger)ulong.MaxValue) + random.NextULong(ulong.MaxValue) + 1); value = (UInt128)(((BigInteger)ulong.MaxValue) + overflow + 1);
} }
catch (Exception) catch (Exception)
{ {
Assert.Fail(); Assert.Fail();
return; return;
} }
Assert.AreEqual(value, (ulong)value); Assert.AreEqual(overflow, (ulong)value);
Assert.Fail();
} }
[TestMethod] [TestMethod]
......
...@@ -95,8 +95,6 @@ namespace PcapDotNet.Base ...@@ -95,8 +95,6 @@ namespace PcapDotNet.Base
/// <returns>The 64 bit value converted from the 128 bit value.</returns> /// <returns>The 64 bit value converted from the 128 bit value.</returns>
public static explicit operator ulong(UInt128 value) public static explicit operator ulong(UInt128 value)
{ {
if (value._mostSignificant != 0)
throw new OverflowException("Value was too large for a UInt64.");
return value._leastSignificant; return value._leastSignificant;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment