-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Remove a few unsafe bits in S.P.Uri, S.N.Ping, System.Transactions.Local #116281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Tagging subscribers to this area: @dotnet/ncl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR removes several unsafe
code paths across three libraries by adopting safer constructs and modern C# features.
- Replace fixed buffers in Xactopt marshalling with
InlineArray
and safe spans - Refactor
IPv4AddressHelper.ParseCanonicalName
to eliminate pointer math and use spans - Remove
unsafe
methods in Ping.RawSocket, replacing pointer-based socket options with spans
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
File | Description |
---|---|
System/Transactions/DtcProxyShim/Xactopt.cs | Switched from unsafe fixed byte buffer to InlineArray , removed unsafe from marshaller methods |
System.Private.Uri/src/System/UriExt.cs | Dropped unused unsafe modifier from GetRelativeSerializationString |
System.Private.Uri/src/System/IPv4AddressHelper.cs | Rewrote ParseCanonicalName to use spans instead of stackalloc pointers and removed obsolete Parse |
System.Net.Ping/src/System/Net/NetworkInformation/Ping.RawSocket.cs | Removed unsafe contexts in raw socket setup and replaced pointer options with ReadOnlySpan<byte> |
Comments suppressed due to low confidence (2)
src/libraries/System.Net.Ping/src/System/Net/NetworkInformation/Ping.RawSocket.cs:109
- [nitpick] The variable name
opt
is ambiguous. Consider a more descriptive name likerecvErrOptionValue
oroptionBytes
to clarify its purpose.
ReadOnlySpan<byte> opt = BitConverter.IsLittleEndian ? [1, 0, 0, 0] : [0, 0, 0, 1];
src/libraries/System.Private.Uri/src/System/IPv4AddressHelper.cs:30
- This array literal creates a heap-allocated array before converting to a Span. For a small fixed-size buffer, consider using stackalloc, e.g.:
Span<byte> numbers = stackalloc byte[NumberOfLabels] { ... };
to avoid heap allocations.
Span<byte> numbers =
diffs (size regression in ParseCanonicalName is due to inlining of Parse)