Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pcap-Net
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Pcap-Net
Commits
fa000133
Commit
fa000133
authored
Apr 25, 2014
by
Brickner_cp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cast from UInt128 to ulong no longer throws an overflow exception if the value is too big.
parent
263d9dbc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
3 additions
and
6 deletions
+3
-6
UInt128Tests.cs
PcapDotNet/src/PcapDotNet.Base.Test/UInt128Tests.cs
+3
-4
UInt128.cs
PcapDotNet/src/PcapDotNet.Base/UInt128.cs
+0
-2
No files found.
PcapDotNet/src/PcapDotNet.Base.Test/UInt128Tests.cs
View file @
fa000133
...
@@ -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
]
...
...
PcapDotNet/src/PcapDotNet.Base/UInt128.cs
View file @
fa000133
...
@@ -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
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment