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
}
[TestMethod]
[ExpectedException(typeof(OverflowException), AllowDerivedTypes = false)]
public void CastToULongOverflow()
{
Random random = new Random();
UInt128 value;
ulong overflow = random.NextULong(ulong.MaxValue);
try
{
value = (UInt128)(((BigInteger)ulong.MaxValue) + random.NextULong(ulong.MaxValue) + 1);
value = (UInt128)(((BigInteger)ulong.MaxValue) + overflow + 1);
}
catch (Exception)
{
Assert.Fail();
return;
}
Assert.AreEqual(value, (ulong)value);
Assert.Fail();
Assert.AreEqual(overflow, (ulong)value);
}
[TestMethod]
......
......@@ -95,8 +95,6 @@ namespace PcapDotNet.Base
/// <returns>The 64 bit value converted from the 128 bit value.</returns>
public static explicit operator ulong(UInt128 value)
{
if (value._mostSignificant != 0)
throw new OverflowException("Value was too large for a UInt64.");
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