From a0d37db84031a188c78017f121e44c51314761cd Mon Sep 17 00:00:00 2001 From: Buyaa Namnan Date: Mon, 26 Feb 2024 15:29:52 -0800 Subject: [PATCH 1/7] Do not compare Span with null --- .../src/Internal/Runtime/InteropServices/ComActivator.cs | 1 - .../src/System/Reflection/Emit/DynamicILGenerator.cs | 2 +- .../Reflection/Runtime/MethodInfos/CustomMethodInvoker.cs | 2 +- .../Interop.SecKeyRef.macOS.cs | 2 +- .../src/System/Net/Http/aspnetcore/Http2/Hpack/Huffman.cs | 2 +- src/libraries/Common/src/System/Number.Parsing.Common.cs | 2 +- .../src/System/IO/FileSystemWatcher.Linux.cs | 2 +- .../src/System/IO/Packaging/ContentType.cs | 2 +- .../System/Linq/Expressions/Interpreter/InstructionList.cs | 1 - .../System.Net.Primitives/src/System/Net/IPAddress.cs | 2 +- .../System.Net.Primitives/src/System/Net/IPAddressParser.cs | 2 +- .../src/System/Net/Sockets/SocketPal.Unix.cs | 6 +++--- .../src/System/Globalization/TimeSpanFormat.cs | 4 ++-- .../System.Private.CoreLib/src/System/Number.Formatting.cs | 4 ++-- .../src/System/Security/Cryptography/HashProviderCng.cs | 2 +- .../Cryptography/X509Certificates/CertificateRequest.cs | 2 +- .../Cryptography/X509Certificates/X500NameEncoder.cs | 2 +- .../src/System/Text/Json/Document/JsonDocument.Parse.cs | 2 -- 18 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs index db8d4ead4659b9..77f64abd1b42c0 100644 --- a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs +++ b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs @@ -203,7 +203,6 @@ private static void ClassRegistrationScenarioForType(ComActivationContext cxt, b // Finally validate signature ReadOnlySpan methParams = method.GetParametersAsSpan(); if (method.ReturnType != typeof(void) - || methParams == null || methParams.Length != 1 || (methParams[0].ParameterType != typeof(string) && methParams[0].ParameterType != typeof(Type))) { diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/DynamicILGenerator.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/DynamicILGenerator.cs index 2b695f1baf5b0f..327113c63f9a3c 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/DynamicILGenerator.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/DynamicILGenerator.cs @@ -417,7 +417,7 @@ private int GetMemberRefToken(MethodInfo methodInfo, Type[]? optionalParameterTy throw new ArgumentException(SR.Argument_MustBeRuntimeMethodInfo, nameof(methodInfo)); ReadOnlySpan paramInfo = methodInfo.GetParametersAsSpan(); - if (paramInfo != null && paramInfo.Length != 0) + if (paramInfo.Length != 0) { parameterTypes = new Type[paramInfo.Length]; requiredCustomModifiers = new Type[parameterTypes.Length][]; diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/MethodInfos/CustomMethodInvoker.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/MethodInfos/CustomMethodInvoker.cs index fbf56e6e4603d2..f2c15681c288fe 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/MethodInfos/CustomMethodInvoker.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/MethodInfos/CustomMethodInvoker.cs @@ -36,7 +36,7 @@ public CustomMethodInvoker(Type thisType, Type[] parameterTypes, InvokerOptions if (!(thisObject == null && 0 != (_options & InvokerOptions.AllowNullThis))) ValidateThis(thisObject, _thisType.TypeHandle); - int argCount = (arguments != null) ? arguments.Length : 0; + int argCount = arguments.Length; if (argCount != _parameterTypes.Length) throw new TargetParameterCountException(); diff --git a/src/libraries/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.SecKeyRef.macOS.cs b/src/libraries/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.SecKeyRef.macOS.cs index e4bca886045c90..0113b912b789c3 100644 --- a/src/libraries/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.SecKeyRef.macOS.cs +++ b/src/libraries/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.SecKeyRef.macOS.cs @@ -36,7 +36,7 @@ private static partial int AppleCryptoNative_SecKeyImportEphemeral( internal static SafeSecKeyRefHandle ImportEphemeralKey(ReadOnlySpan keyBlob, bool hasPrivateKey) { - Debug.Assert(keyBlob != null); + Debug.Assert(keyBlob != default); SafeSecKeyRefHandle keyHandle; int osStatus; diff --git a/src/libraries/Common/src/System/Net/Http/aspnetcore/Http2/Hpack/Huffman.cs b/src/libraries/Common/src/System/Net/Http/aspnetcore/Http2/Hpack/Huffman.cs index b23b7e63529d8a..980bfbc3579995 100644 --- a/src/libraries/Common/src/System/Net/Http/aspnetcore/Http2/Hpack/Huffman.cs +++ b/src/libraries/Common/src/System/Net/Http/aspnetcore/Http2/Hpack/Huffman.cs @@ -677,7 +677,7 @@ public static int Decode(ReadOnlySpan src, ref byte[] dstArray) // see comments in GenerateDecodingLookupTree() describing decoding table Span dst = dstArray; - Debug.Assert(dst != null && dst.Length > 0); + Debug.Assert(dst.Length > 0); ushort[] decodingTree = s_decodingTree; diff --git a/src/libraries/Common/src/System/Number.Parsing.Common.cs b/src/libraries/Common/src/System/Number.Parsing.Common.cs index 16e9f777f3464b..abf4a975c424ae 100644 --- a/src/libraries/Common/src/System/Number.Parsing.Common.cs +++ b/src/libraries/Common/src/System/Number.Parsing.Common.cs @@ -336,7 +336,7 @@ internal enum ParsingStatus private static unsafe TChar* MatchChars(TChar* p, TChar* pEnd, ReadOnlySpan value) where TChar : unmanaged, IUtfChar { - Debug.Assert((p != null) && (pEnd != null) && (p <= pEnd) && (value != null)); + Debug.Assert((p != null) && (pEnd != null) && (p <= pEnd) && (value != default)); fixed (TChar* stringPointer = &MemoryMarshal.GetReference(value)) { diff --git a/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.Linux.cs b/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.Linux.cs index 65dcefea25dafb..5a443b08e0bdb8 100644 --- a/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.Linux.cs +++ b/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.Linux.cs @@ -720,7 +720,7 @@ private bool ProcessEvent(NotifyEvent nextEvent, ref ReadOnlySpan previous break; case Interop.Sys.NotifyEvents.IN_MOVED_TO: - if (previousEventName != null) + if (previousEventName.IsEmpty) { // If the previous name from IN_MOVED_FROM is non-null, then this is a rename. watcher.NotifyRenameEventArgs(WatcherChangeTypes.Renamed, expandedName, previousEventName); diff --git a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ContentType.cs b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ContentType.cs index c6fe72e7f047df..751514933b5ecd 100644 --- a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ContentType.cs +++ b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ContentType.cs @@ -351,7 +351,7 @@ private void ParseParameterAndValue(ReadOnlySpan parameterAndValue) /// private static int GetLengthOfParameterValue(ReadOnlySpan s, int startIndex) { - Debug.Assert(s != null); + Debug.Assert(s != default); int length; diff --git a/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/InstructionList.cs b/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/InstructionList.cs index c9d525a81a0827..148e24f812e07e 100644 --- a/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/InstructionList.cs +++ b/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/InstructionList.cs @@ -44,7 +44,6 @@ internal sealed class DebugView public DebugView(InstructionArray array) { - ArgumentNullException.ThrowIfNull(array); _array = array; } diff --git a/src/libraries/System.Net.Primitives/src/System/Net/IPAddress.cs b/src/libraries/System.Net.Primitives/src/System/Net/IPAddress.cs index bdd381fc04901c..91fe445aaab383 100644 --- a/src/libraries/System.Net.Primitives/src/System/Net/IPAddress.cs +++ b/src/libraries/System.Net.Primitives/src/System/Net/IPAddress.cs @@ -142,7 +142,7 @@ public IPAddress(ReadOnlySpan address, long scopeid) internal IPAddress(ReadOnlySpan numbers, uint scopeid) { - Debug.Assert(numbers != null); + Debug.Assert(numbers != default); Debug.Assert(numbers.Length == NumberOfLabels); _numbers = numbers.ToArray(); diff --git a/src/libraries/System.Net.Primitives/src/System/Net/IPAddressParser.cs b/src/libraries/System.Net.Primitives/src/System/Net/IPAddressParser.cs index 964cd4308366ab..4db353a1d4f17a 100644 --- a/src/libraries/System.Net.Primitives/src/System/Net/IPAddressParser.cs +++ b/src/libraries/System.Net.Primitives/src/System/Net/IPAddressParser.cs @@ -67,7 +67,7 @@ private static unsafe bool TryParseIpv4(ReadOnlySpan ipSpan, out long addr private static unsafe bool TryParseIPv6(ReadOnlySpan ipSpan, Span numbers, int numbersLength, out uint scope) { - Debug.Assert(numbers != null); + Debug.Assert(numbers != default); Debug.Assert(numbersLength >= IPAddressParserStatics.IPv6AddressShorts); int end = ipSpan.Length; diff --git a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Unix.cs b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Unix.cs index d2ac959e0b4c73..18b00877b31899 100644 --- a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Unix.cs +++ b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Unix.cs @@ -528,7 +528,7 @@ private static unsafe int SysReceiveMessageFrom( out SocketFlags receivedFlags, out IPPacketInformation ipPacketInformation, out Interop.Error errno) { Debug.Assert(socket.IsSocket); - Debug.Assert(socketAddress != null, "Expected non-null socketAddress"); + Debug.Assert(socketAddress != default, "Expected non-default socketAddress"); int buffersCount = buffers.Count; bool allocOnStack = buffersCount <= IovStackThreshold; @@ -810,7 +810,7 @@ public static unsafe bool TryCompleteReceiveFrom(SafeSocketHandle socket, Span { sent = buffers != null ? SysSend(socket, flags, buffers, ref bufferIndex, ref offset, socketAddress, out errno) : - socketAddress == null ? SysSend(socket, flags, buffer, ref offset, ref count, out errno) : + socketAddress.IsEmpty ? SysSend(socket, flags, buffer, ref offset, ref count, out errno) : SysSend(socket, flags, buffer, ref offset, ref count, socketAddress, out errno); } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/TimeSpanFormat.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/TimeSpanFormat.cs index 4e11f14c80903b..9a80847f44f9e5 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/TimeSpanFormat.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/TimeSpanFormat.cs @@ -268,12 +268,12 @@ internal static unsafe bool TryFormatStandard(TimeSpan value, StandardFor // Write fraction and separator, if necessary if (fractionDigits != 0) { - Debug.Assert(format == StandardFormat.C || decimalSeparator != null); + Debug.Assert(format == StandardFormat.C || !decimalSeparator.IsEmpty); if (format == StandardFormat.C) { *p++ = TChar.CastFrom('.'); } - else if (decimalSeparator!.Length == 1) + else if (decimalSeparator.Length == 1) { *p++ = decimalSeparator[0]; } diff --git a/src/libraries/System.Private.CoreLib/src/System/Number.Formatting.cs b/src/libraries/System.Private.CoreLib/src/System/Number.Formatting.cs index 3bb61ebcf736f6..c01fad82f51b13 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Number.Formatting.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Number.Formatting.cs @@ -3498,7 +3498,7 @@ private static unsafe void FormatFixed( { if (groupDigits != null) { - Debug.Assert(sGroup != null, "Must be null when groupDigits != null"); + Debug.Assert(sGroup != default, "Must not be default when groupDigits != null"); int groupSizeIndex = 0; // Index into the groupDigits array. int bufferSize = digPos; // The length of the result buffer string. int groupSize = 0; // The current group size. @@ -3583,7 +3583,7 @@ private static unsafe void FormatFixed( if (nMaxDigits > 0) { - Debug.Assert(sDecimal != null); + Debug.Assert(sDecimal != default); vlb.Append(sDecimal); if ((digPos < 0) && (nMaxDigits > 0)) { diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/HashProviderCng.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/HashProviderCng.cs index 831b846a74447e..36f4767e9939e6 100644 --- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/HashProviderCng.cs +++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/HashProviderCng.cs @@ -39,7 +39,7 @@ internal HashProviderCng(string hashAlgId, ReadOnlySpan key, bool isHmac) // So keep hHash trapped in this scope to prevent (mis-)use of it. { SafeBCryptHashHandle hHash; - NTSTATUS ntStatus = Interop.BCrypt.BCryptCreateHash(_hAlgorithm, out hHash, IntPtr.Zero, 0, key, key == null ? 0 : key.Length, BCryptCreateHashFlags.BCRYPT_HASH_REUSABLE_FLAG); + NTSTATUS ntStatus = Interop.BCrypt.BCryptCreateHash(_hAlgorithm, out hHash, IntPtr.Zero, 0, key, key.Length, BCryptCreateHashFlags.BCRYPT_HASH_REUSABLE_FLAG); if (ntStatus == NTSTATUS.STATUS_INVALID_PARAMETER) { hHash.Dispose(); diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/CertificateRequest.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/CertificateRequest.cs index c3084c964d7dc2..405d37188e3729 100644 --- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/CertificateRequest.cs +++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/CertificateRequest.cs @@ -812,7 +812,7 @@ public X509Certificate2 Create( if (notAfter < notBefore) throw new ArgumentException(SR.Cryptography_CertReq_DatesReversed); - if (serialNumber == null || serialNumber.Length < 1) + if (serialNumber.Length < 1) throw new ArgumentException(SR.Arg_EmptyOrNullArray, nameof(serialNumber)); byte[] signatureAlgorithm = generator.GetSignatureAlgorithmIdentifier(HashAlgorithm); diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X500NameEncoder.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X500NameEncoder.cs index d2509eca3c3da1..4c4eebc55fab5c 100644 --- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X500NameEncoder.cs +++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X500NameEncoder.cs @@ -444,7 +444,7 @@ private static List ParseDistinguishedName( // then some whitespace. case ParseState.MaybeEndQuote: case ParseState.SeekComma: - Debug.Assert(tagOid != null); + Debug.Assert(tagOid != default); Debug.Assert(valueStart != -1); Debug.Assert(valueEnd != -1); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonDocument.Parse.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonDocument.Parse.cs index e5719888d80a79..f9b1fffd4243b2 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonDocument.Parse.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonDocument.Parse.cs @@ -165,8 +165,6 @@ internal static JsonDocument ParseValue(Stream utf8Json, JsonDocumentOptions opt internal static JsonDocument ParseValue(ReadOnlySpan utf8Json, JsonDocumentOptions options) { - Debug.Assert(utf8Json != null); - byte[] owned = new byte[utf8Json.Length]; utf8Json.CopyTo(owned); From a5a5ac1fd95d5cc6b346bcb9df3bcbc64dbeb223 Mon Sep 17 00:00:00 2001 From: Buyaa Namnan Date: Mon, 26 Feb 2024 16:54:28 -0800 Subject: [PATCH 2/7] Update src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.Linux.cs --- .../src/System/IO/FileSystemWatcher.Linux.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.Linux.cs b/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.Linux.cs index 5a443b08e0bdb8..2101c0a6410b3e 100644 --- a/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.Linux.cs +++ b/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.Linux.cs @@ -720,7 +720,7 @@ private bool ProcessEvent(NotifyEvent nextEvent, ref ReadOnlySpan previous break; case Interop.Sys.NotifyEvents.IN_MOVED_TO: - if (previousEventName.IsEmpty) + if (!previousEventName.IsEmpty) { // If the previous name from IN_MOVED_FROM is non-null, then this is a rename. watcher.NotifyRenameEventArgs(WatcherChangeTypes.Renamed, expandedName, previousEventName); From e58800c429814d20f121c882a789a04b983ce8fc Mon Sep 17 00:00:00 2001 From: Buyaa Namnan Date: Mon, 26 Feb 2024 17:24:01 -0800 Subject: [PATCH 3/7] Apply suggestions from code review Co-authored-by: Stephen Toub --- src/libraries/Common/src/System/Number.Parsing.Common.cs | 2 +- .../System.IO.Packaging/src/System/IO/Packaging/ContentType.cs | 1 - src/libraries/System.Net.Primitives/src/System/Net/IPAddress.cs | 1 - .../System.Net.Primitives/src/System/Net/IPAddressParser.cs | 1 - .../System.Net.Sockets/src/System/Net/Sockets/SocketPal.Unix.cs | 2 -- .../src/System/Globalization/TimeSpanFormat.cs | 1 - .../System.Private.CoreLib/src/System/Number.Formatting.cs | 2 -- 7 files changed, 1 insertion(+), 9 deletions(-) diff --git a/src/libraries/Common/src/System/Number.Parsing.Common.cs b/src/libraries/Common/src/System/Number.Parsing.Common.cs index abf4a975c424ae..e43cbe14c29226 100644 --- a/src/libraries/Common/src/System/Number.Parsing.Common.cs +++ b/src/libraries/Common/src/System/Number.Parsing.Common.cs @@ -336,7 +336,7 @@ internal enum ParsingStatus private static unsafe TChar* MatchChars(TChar* p, TChar* pEnd, ReadOnlySpan value) where TChar : unmanaged, IUtfChar { - Debug.Assert((p != null) && (pEnd != null) && (p <= pEnd) && (value != default)); + Debug.Assert((p != null) && (pEnd != null) && (p <= pEnd)); fixed (TChar* stringPointer = &MemoryMarshal.GetReference(value)) { diff --git a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ContentType.cs b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ContentType.cs index 751514933b5ecd..b06e022e4b3119 100644 --- a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ContentType.cs +++ b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ContentType.cs @@ -351,7 +351,6 @@ private void ParseParameterAndValue(ReadOnlySpan parameterAndValue) /// private static int GetLengthOfParameterValue(ReadOnlySpan s, int startIndex) { - Debug.Assert(s != default); int length; diff --git a/src/libraries/System.Net.Primitives/src/System/Net/IPAddress.cs b/src/libraries/System.Net.Primitives/src/System/Net/IPAddress.cs index 91fe445aaab383..48f424407b400c 100644 --- a/src/libraries/System.Net.Primitives/src/System/Net/IPAddress.cs +++ b/src/libraries/System.Net.Primitives/src/System/Net/IPAddress.cs @@ -142,7 +142,6 @@ public IPAddress(ReadOnlySpan address, long scopeid) internal IPAddress(ReadOnlySpan numbers, uint scopeid) { - Debug.Assert(numbers != default); Debug.Assert(numbers.Length == NumberOfLabels); _numbers = numbers.ToArray(); diff --git a/src/libraries/System.Net.Primitives/src/System/Net/IPAddressParser.cs b/src/libraries/System.Net.Primitives/src/System/Net/IPAddressParser.cs index 4db353a1d4f17a..afe80e3cd5b829 100644 --- a/src/libraries/System.Net.Primitives/src/System/Net/IPAddressParser.cs +++ b/src/libraries/System.Net.Primitives/src/System/Net/IPAddressParser.cs @@ -67,7 +67,6 @@ private static unsafe bool TryParseIpv4(ReadOnlySpan ipSpan, out long addr private static unsafe bool TryParseIPv6(ReadOnlySpan ipSpan, Span numbers, int numbersLength, out uint scope) { - Debug.Assert(numbers != default); Debug.Assert(numbersLength >= IPAddressParserStatics.IPv6AddressShorts); int end = ipSpan.Length; diff --git a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Unix.cs b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Unix.cs index 18b00877b31899..837743dfa34478 100644 --- a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Unix.cs +++ b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Unix.cs @@ -528,7 +528,6 @@ private static unsafe int SysReceiveMessageFrom( out SocketFlags receivedFlags, out IPPacketInformation ipPacketInformation, out Interop.Error errno) { Debug.Assert(socket.IsSocket); - Debug.Assert(socketAddress != default, "Expected non-default socketAddress"); int buffersCount = buffers.Count; bool allocOnStack = buffersCount <= IovStackThreshold; @@ -810,7 +809,6 @@ public static unsafe bool TryCompleteReceiveFrom(SafeSocketHandle socket, Span(TimeSpan value, StandardFor // Write fraction and separator, if necessary if (fractionDigits != 0) { - Debug.Assert(format == StandardFormat.C || !decimalSeparator.IsEmpty); if (format == StandardFormat.C) { *p++ = TChar.CastFrom('.'); diff --git a/src/libraries/System.Private.CoreLib/src/System/Number.Formatting.cs b/src/libraries/System.Private.CoreLib/src/System/Number.Formatting.cs index c01fad82f51b13..c8884036777343 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Number.Formatting.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Number.Formatting.cs @@ -3498,7 +3498,6 @@ private static unsafe void FormatFixed( { if (groupDigits != null) { - Debug.Assert(sGroup != default, "Must not be default when groupDigits != null"); int groupSizeIndex = 0; // Index into the groupDigits array. int bufferSize = digPos; // The length of the result buffer string. int groupSize = 0; // The current group size. @@ -3583,7 +3582,6 @@ private static unsafe void FormatFixed( if (nMaxDigits > 0) { - Debug.Assert(sDecimal != default); vlb.Append(sDecimal); if ((digPos < 0) && (nMaxDigits > 0)) { From 8bc6dd8317acd677cff1ca2090b3cf11a4e7be1f Mon Sep 17 00:00:00 2001 From: Buyaa Namnan Date: Mon, 26 Feb 2024 17:30:55 -0800 Subject: [PATCH 4/7] Apply suggestions from code review Co-authored-by: Stephen Toub --- .../System.IO.Packaging/src/System/IO/Packaging/ContentType.cs | 1 - .../Security/Cryptography/X509Certificates/X500NameEncoder.cs | 1 - 2 files changed, 2 deletions(-) diff --git a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ContentType.cs b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ContentType.cs index b06e022e4b3119..894fd4826aa80d 100644 --- a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ContentType.cs +++ b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ContentType.cs @@ -351,7 +351,6 @@ private void ParseParameterAndValue(ReadOnlySpan parameterAndValue) /// private static int GetLengthOfParameterValue(ReadOnlySpan s, int startIndex) { - int length; //if the parameter value does not start with a '"' then, diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X500NameEncoder.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X500NameEncoder.cs index 4c4eebc55fab5c..865b18e0951888 100644 --- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X500NameEncoder.cs +++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X500NameEncoder.cs @@ -444,7 +444,6 @@ private static List ParseDistinguishedName( // then some whitespace. case ParseState.MaybeEndQuote: case ParseState.SeekComma: - Debug.Assert(tagOid != default); Debug.Assert(valueStart != -1); Debug.Assert(valueEnd != -1); From a80350fa96d36c55939d2c7a9a2906ed87786239 Mon Sep 17 00:00:00 2001 From: Buyaa Namnan Date: Tue, 27 Feb 2024 14:16:50 -0800 Subject: [PATCH 5/7] Use Unsafe.IsNullRef(ref MemoryMarshal.GetReference(span)) --- .../Interop.SecKeyRef.macOS.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libraries/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.SecKeyRef.macOS.cs b/src/libraries/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.SecKeyRef.macOS.cs index 0113b912b789c3..76b74bb2be09b4 100644 --- a/src/libraries/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.SecKeyRef.macOS.cs +++ b/src/libraries/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.SecKeyRef.macOS.cs @@ -3,6 +3,7 @@ using System; using System.Diagnostics; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Security.Cryptography; using System.Security.Cryptography.Apple; @@ -36,7 +37,7 @@ private static partial int AppleCryptoNative_SecKeyImportEphemeral( internal static SafeSecKeyRefHandle ImportEphemeralKey(ReadOnlySpan keyBlob, bool hasPrivateKey) { - Debug.Assert(keyBlob != default); + Debug.Assert(Unsafe.IsNullRef(ref MemoryMarshal.GetReference(keyBlob))); SafeSecKeyRefHandle keyHandle; int osStatus; From b9470e4ebe82dbb2cdfcd15c479ca44006af88ae Mon Sep 17 00:00:00 2001 From: Buyaa Namnan Date: Tue, 27 Feb 2024 14:20:18 -0800 Subject: [PATCH 6/7] Update src/libraries/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.SecKeyRef.macOS.cs Co-authored-by: Kevin Jones --- .../Interop.SecKeyRef.macOS.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.SecKeyRef.macOS.cs b/src/libraries/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.SecKeyRef.macOS.cs index 76b74bb2be09b4..74f4ccd2fafb9f 100644 --- a/src/libraries/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.SecKeyRef.macOS.cs +++ b/src/libraries/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.SecKeyRef.macOS.cs @@ -37,7 +37,7 @@ private static partial int AppleCryptoNative_SecKeyImportEphemeral( internal static SafeSecKeyRefHandle ImportEphemeralKey(ReadOnlySpan keyBlob, bool hasPrivateKey) { - Debug.Assert(Unsafe.IsNullRef(ref MemoryMarshal.GetReference(keyBlob))); + Debug.Assert(!Unsafe.IsNullRef(ref MemoryMarshal.GetReference(keyBlob))); SafeSecKeyRefHandle keyHandle; int osStatus; From 9f9c37cdb3c54c1fa9189134449dedb4e6acec9c Mon Sep 17 00:00:00 2001 From: Buyaa Namnan Date: Wed, 28 Feb 2024 11:17:16 -0800 Subject: [PATCH 7/7] Update src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.Linux.cs Co-authored-by: Jan Kotas --- .../src/System/IO/FileSystemWatcher.Linux.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.Linux.cs b/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.Linux.cs index 2101c0a6410b3e..b09e0197e04471 100644 --- a/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.Linux.cs +++ b/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.Linux.cs @@ -722,7 +722,7 @@ private bool ProcessEvent(NotifyEvent nextEvent, ref ReadOnlySpan previous case Interop.Sys.NotifyEvents.IN_MOVED_TO: if (!previousEventName.IsEmpty) { - // If the previous name from IN_MOVED_FROM is non-null, then this is a rename. + // If the previous name from IN_MOVED_FROM is non-empty, then this is a rename. watcher.NotifyRenameEventArgs(WatcherChangeTypes.Renamed, expandedName, previousEventName); } else