Skip to content
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

Do not compare Span<T> with null #98958

Merged
merged 10 commits into from
Feb 28, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ private static void ClassRegistrationScenarioForType(ComActivationContext cxt, b
// Finally validate signature
ReadOnlySpan<ParameterInfo> methParams = method.GetParametersAsSpan();
if (method.ReturnType != typeof(void)
|| methParams == null
|| methParams.Length != 1
|| (methParams[0].ParameterType != typeof(string) && methParams[0].ParameterType != typeof(Type)))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ private int GetMemberRefToken(MethodInfo methodInfo, Type[]? optionalParameterTy
throw new ArgumentException(SR.Argument_MustBeRuntimeMethodInfo, nameof(methodInfo));

ReadOnlySpan<ParameterInfo> paramInfo = methodInfo.GetParametersAsSpan();
if (paramInfo != null && paramInfo.Length != 0)
if (paramInfo.Length != 0)
{
parameterTypes = new Type[paramInfo.Length];
requiredCustomModifiers = new Type[parameterTypes.Length][];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -36,7 +37,7 @@ private static partial int AppleCryptoNative_SecKeyImportEphemeral(

internal static SafeSecKeyRefHandle ImportEphemeralKey(ReadOnlySpan<byte> keyBlob, bool hasPrivateKey)
{
Debug.Assert(keyBlob != null);
Debug.Assert(!Unsafe.IsNullRef(ref MemoryMarshal.GetReference(keyBlob)));

SafeSecKeyRefHandle keyHandle;
int osStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ public static int Decode(ReadOnlySpan<byte> src, ref byte[] dstArray)
// see comments in GenerateDecodingLookupTree() describing decoding table

Span<byte> dst = dstArray;
Debug.Assert(dst != null && dst.Length > 0);
Debug.Assert(dst.Length > 0);

ushort[] decodingTree = s_decodingTree;

Expand Down
2 changes: 1 addition & 1 deletion src/libraries/Common/src/System/Number.Parsing.Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ internal enum ParsingStatus
private static unsafe TChar* MatchChars<TChar>(TChar* p, TChar* pEnd, ReadOnlySpan<TChar> value)
where TChar : unmanaged, IUtfChar<TChar>
{
Debug.Assert((p != null) && (pEnd != null) && (p <= pEnd) && (value != null));
Debug.Assert((p != null) && (pEnd != null) && (p <= pEnd));

fixed (TChar* stringPointer = &MemoryMarshal.GetReference(value))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -720,9 +720,9 @@ private bool ProcessEvent(NotifyEvent nextEvent, ref ReadOnlySpan<char> 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.
// If the previous name from IN_MOVED_FROM is non-empty, then this is a rename.
watcher.NotifyRenameEventArgs(WatcherChangeTypes.Renamed, expandedName, previousEventName);
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,6 @@ private void ParseParameterAndValue(ReadOnlySpan<char> parameterAndValue)
/// <returns></returns>
private static int GetLengthOfParameterValue(ReadOnlySpan<char> s, int startIndex)
{
Debug.Assert(s != null);

int length;

//if the parameter value does not start with a '"' then,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ public IPAddress(ReadOnlySpan<byte> address, long scopeid)

internal IPAddress(ReadOnlySpan<ushort> numbers, uint scopeid)
{
Debug.Assert(numbers != null);
Debug.Assert(numbers.Length == NumberOfLabels);

_numbers = numbers.ToArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ private static unsafe bool TryParseIpv4(ReadOnlySpan<char> ipSpan, out long addr

private static unsafe bool TryParseIPv6(ReadOnlySpan<char> ipSpan, Span<ushort> numbers, int numbersLength, out uint scope)
{
Debug.Assert(numbers != null);
Debug.Assert(numbersLength >= IPAddressParserStatics.IPv6AddressShorts);

int end = ipSpan.Length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 != null, "Expected non-null socketAddress");

int buffersCount = buffers.Count;
bool allocOnStack = buffersCount <= IovStackThreshold;
Expand Down Expand Up @@ -810,7 +809,6 @@ public static unsafe bool TryCompleteReceiveFrom(SafeSocketHandle socket, Span<b
{
Debug.Assert(flags == SocketFlags.None);
Debug.Assert(buffers == null);
Debug.Assert(socketAddress == null);

receivedFlags = default;
received = SysRead(socket, buffer, out errno);
Expand Down Expand Up @@ -956,7 +954,7 @@ public static bool TryCompleteSendTo(SafeSocketHandle socket, ReadOnlySpan<byte>
{
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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,11 @@ internal static unsafe bool TryFormatStandard<TChar>(TimeSpan value, StandardFor
// Write fraction and separator, if necessary
if (fractionDigits != 0)
{
Debug.Assert(format == StandardFormat.C || decimalSeparator != null);
if (format == StandardFormat.C)
{
*p++ = TChar.CastFrom('.');
}
else if (decimalSeparator!.Length == 1)
else if (decimalSeparator.Length == 1)
{
*p++ = decimalSeparator[0];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3498,7 +3498,6 @@ private static unsafe void FormatFixed<TChar>(
{
if (groupDigits != null)
{
Debug.Assert(sGroup != null, "Must be null 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.
Expand Down Expand Up @@ -3583,7 +3582,6 @@ private static unsafe void FormatFixed<TChar>(

if (nMaxDigits > 0)
{
Debug.Assert(sDecimal != null);
vlb.Append(sDecimal);
if ((digPos < 0) && (nMaxDigits > 0))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ internal HashProviderCng(string hashAlgId, ReadOnlySpan<byte> 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);
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved
if (ntStatus == NTSTATUS.STATUS_INVALID_PARAMETER)
{
hHash.Dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,6 @@ private static List<byte[]> ParseDistinguishedName(
// then some whitespace.
case ParseState.MaybeEndQuote:
case ParseState.SeekComma:
Debug.Assert(tagOid != null);
Debug.Assert(valueStart != -1);
Debug.Assert(valueEnd != -1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,6 @@ internal static JsonDocument ParseValue(Stream utf8Json, JsonDocumentOptions opt

internal static JsonDocument ParseValue(ReadOnlySpan<byte> utf8Json, JsonDocumentOptions options)
{
Debug.Assert(utf8Json != null);

byte[] owned = new byte[utf8Json.Length];
utf8Json.CopyTo(owned);

Expand Down
Loading