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

Remove now-redundant Debug.Assert messages #105167

Merged
merged 1 commit into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1369,9 +1369,9 @@ internal void MarkFinallyAddr(int finallyAddr, int endCatchAddr)

internal void Done(int endAddr)
{
Debug.Assert(m_currentCatch > 0, "m_currentCatch > 0");
Debug.Assert(m_catchAddr[m_currentCatch - 1] > 0, "m_catchAddr[m_currentCatch-1] > 0");
Debug.Assert(m_catchEndAddr[m_currentCatch - 1] == -1, "m_catchEndAddr[m_currentCatch-1] == -1");
Debug.Assert(m_currentCatch > 0);
Debug.Assert(m_catchAddr[m_currentCatch - 1] > 0);
Debug.Assert(m_catchEndAddr[m_currentCatch - 1] == -1);
m_catchEndAddr[m_currentCatch - 1] = endAddr;
m_currentState = State_Done;
}
Expand Down Expand Up @@ -1447,8 +1447,8 @@ internal Label GetFinallyEndLabel()
internal bool IsInner(__ExceptionInfo exc)
{
Debug.Assert(exc != null);
Debug.Assert(m_currentCatch > 0, "m_currentCatch > 0");
Debug.Assert(exc.m_currentCatch > 0, "exc.m_currentCatch > 0");
Debug.Assert(m_currentCatch > 0);
Debug.Assert(exc.m_currentCatch > 0);

int exclast = exc.m_currentCatch - 1;
int last = m_currentCatch - 1;
Expand All @@ -1458,8 +1458,7 @@ internal bool IsInner(__ExceptionInfo exc)

if (exc.m_catchEndAddr[exclast] != m_catchEndAddr[last])
return false;
Debug.Assert(exc.GetEndAddress() != GetEndAddress(),
"exc.GetEndAddress() != GetEndAddress()");
Debug.Assert(exc.GetEndAddress() != GetEndAddress());

return exc.GetEndAddress() > GetEndAddress();
}
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/System.Private.CoreLib/src/System/Variant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,14 @@ public Variant(object? obj)
{
vt = VarEnum.VT_ERROR;
obj = (object)(((ErrorWrapper)obj).ErrorCode);
Debug.Assert(obj != null, "obj != null");
Debug.Assert(obj != null);
}
#pragma warning disable 0618 // CurrencyWrapper is obsolete
else if (obj is CurrencyWrapper)
{
vt = VarEnum.VT_CY;
obj = (object)(((CurrencyWrapper)obj).WrappedObject);
Debug.Assert(obj != null, "obj != null");
Debug.Assert(obj != null);
}
#pragma warning restore 0618
else if (obj is BStrWrapper)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ internal static SafeSslHandle AllocateSslHandle(SslAuthenticationOptions sslAuth
SslCertificateTrust trust = sslAuthenticationOptions.CertificateContext!.Trust!;
X509Certificate2Collection certList = (trust._trustList ?? trust._store!.Certificates);

Debug.Assert(certList != null, "certList != null");
Debug.Assert(certList != null);
Span<IntPtr> handles = certList.Count <= 256 ?
stackalloc IntPtr[256] :
new IntPtr[certList.Count];
Expand Down Expand Up @@ -884,8 +884,8 @@ private static void BioWrite(SafeBioHandle bio, ReadOnlySpan<byte> buffer)

private static void SetSslCertificate(SafeSslContextHandle contextPtr, SafeX509Handle certPtr, SafeEvpPKeyHandle keyPtr)
{
Debug.Assert(certPtr != null && !certPtr.IsInvalid, "certPtr != null && !certPtr.IsInvalid");
Debug.Assert(keyPtr != null && !keyPtr.IsInvalid, "keyPtr != null && !keyPtr.IsInvalid");
Debug.Assert(certPtr != null && !certPtr.IsInvalid);
Debug.Assert(keyPtr != null && !keyPtr.IsInvalid);

int retVal = Ssl.SslCtxUseCertificate(contextPtr, certPtr);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static unsafe void InitializeReferencedDomainsList(this SafeLsaMemoryHand
pTrustInformation += domainList.Entries;

long bufferSize = (byte*)pTrustInformation - pRdl;
System.Diagnostics.Debug.Assert(bufferSize > 0, "bufferSize > 0");
System.Diagnostics.Debug.Assert(bufferSize > 0);
referencedDomains.Initialize((ulong)bufferSize);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public void Dispose()

internal void SetKey(SafeEcKeyHandle key)
{
Debug.Assert(key != null, "key != null");
Debug.Assert(!key.IsInvalid, "!key.IsInvalid");
Debug.Assert(!key.IsClosed, "!key.IsClosed");
Debug.Assert(key != null);
Debug.Assert(!key.IsInvalid);
Debug.Assert(!key.IsClosed);

FreeKey();
_key = new Lazy<SafeEcKeyHandle>(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ internal static byte[] GetNamedCurveBlob(ref ECParameters parameters, bool ecdh)
}

// We better have computed the right allocation size above!
Debug.Assert(offset == blobSize, "offset == blobSize");
Debug.Assert(offset == blobSize);
}
}
return blob;
Expand Down Expand Up @@ -143,7 +143,7 @@ internal static byte[] GetPrimeCurveBlob(ref ECParameters parameters, bool ecdh)
}

// We better have computed the right allocation size above!
Debug.Assert(offset == blobSize, "offset == blobSize");
Debug.Assert(offset == blobSize);
}

return blob;
Expand Down Expand Up @@ -311,7 +311,7 @@ internal static unsafe byte[] GetPrimeCurveParameterBlob(ref ECCurve curve)
}

// We better have computed the right allocation size above!
Debug.Assert(offset == blobSize, "offset == blobSize");
Debug.Assert(offset == blobSize);
}

return blob;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ internal SafeEvpPKeyHandle UpRefKeyHandle()

internal void SetKey(SafeEcKeyHandle key)
{
Debug.Assert(key != null, "key != null");
Debug.Assert(!key.IsInvalid, "!key.IsInvalid");
Debug.Assert(!key.IsClosed, "!key.IsClosed");
Debug.Assert(key != null);
Debug.Assert(!key.IsInvalid);
Debug.Assert(!key.IsClosed);

FreeKey();
_key = new Lazy<SafeEcKeyHandle>(key);
Expand Down
6 changes: 3 additions & 3 deletions src/libraries/Common/tests/System/Net/ManualChunkingStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public ManualChunkingStream(Stream stream, bool chunkWrite)

public async ValueTask CommitWriteAsync(int length)
{
Debug.Assert(length <= PendingWriteLength && length > 0, "length <= PendingWriteLength && length > 0");
Debug.Assert(length <= PendingWriteLength && length > 0);
byte[] buffer = ArrayPool<byte>.Shared.Rent(length);

int read = await _writeBuffer.ReadAsync(buffer.AsMemory(0, length));
Debug.Assert(read == length, "read == length");
Debug.Assert(read == length);
await _innerStream.WriteAsync(buffer, 0, read);
await _innerStream.FlushAsync();

Expand All @@ -46,7 +46,7 @@ public void SetWriteChunking(bool chunking)
byte[] buffer = ArrayPool<byte>.Shared.Rent(PendingWriteLength);

int read = _writeBuffer.Read(buffer.AsSpan(0, PendingWriteLength));
Debug.Assert(PendingWriteLength == 0, "PendingWriteLength == 0");
Debug.Assert(PendingWriteLength == 0);
_innerStream.Write(buffer, 0, read);
_innerStream.Flush();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public SafeDeleteSslContext(SslAuthenticationOptions sslAuthenticationOptions)
SslCertificateTrust trust = sslAuthenticationOptions.CertificateContext!.Trust!;
X509Certificate2Collection certList = (trust._trustList ?? trust._store!.Certificates);

Debug.Assert(certList != null, "certList != null");
Debug.Assert(certList != null);
Span<IntPtr> handles = certList.Count <= 256
? stackalloc IntPtr[256]
: new IntPtr[certList.Count];
Expand Down Expand Up @@ -368,7 +368,7 @@ private static void SetProtocols(SafeSslHandle sslContext, SslProtocols protocol

internal static void SetCertificate(SafeSslHandle sslContext, SslStreamCertificateContext context)
{
Debug.Assert(sslContext != null, "sslContext != null");
Debug.Assert(sslContext != null);

IntPtr[] ptrs = new IntPtr[context!.IntermediateCertificates.Count + 1];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ internal void CloseContext()

private static X509Certificate2? MakeEx(X509Certificate certificate)
{
Debug.Assert(certificate != null, "certificate != null");
Debug.Assert(certificate != null);

if (certificate.GetType() == typeof(X509Certificate2))
{
Expand Down Expand Up @@ -985,7 +985,7 @@ internal void ProcessHandshakeSuccess()
_headerSize = streamSizes.Header;
_trailerSize = streamSizes.Trailer;
_maxDataSize = streamSizes.MaximumMessage;
Debug.Assert(_maxDataSize > 0, "_maxDataSize > 0");
Debug.Assert(_maxDataSize > 0);

SslStreamPal.QueryContextConnectionInfo(_securityContext!, ref _connectionInfo);
#if DEBUG
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public SslBuffer()

public ReadOnlySpan<byte> DecryptedReadOnlySpanSliced(int length)
{
Debug.Assert(length <= DecryptedLength, "length <= DecryptedLength");
Debug.Assert(length <= DecryptedLength);
return _buffer.ActiveSpan.Slice(0, length);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ private void Insert(object key, object? nvalue, bool add)

private void putEntry(Bucket[] newBuckets, object key, object? nvalue, int hashcode)
{
Debug.Assert(hashcode >= 0, "hashcode >= 0"); // make sure collision bit (sign bit) wasn't set.
Debug.Assert(hashcode >= 0); // make sure collision bit (sign bit) wasn't set.

uint seed = (uint)hashcode;
uint incr = unchecked((uint)(1 + ((seed * HashHelpers.HashPrime) % ((uint)newBuckets.Length - 1))));
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.Private.CoreLib/src/System/Decimal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ public static bool TryGetBits(decimal d, Span<int> destination, out int valuesWr

internal static void GetBytes(in decimal d, Span<byte> buffer)
{
Debug.Assert(buffer.Length >= 16, "buffer.Length >= 16");
Debug.Assert(buffer.Length >= 16);

BinaryPrimitives.WriteInt32LittleEndian(buffer, (int)d.Low);
BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(4), (int)d.Mid);
Expand All @@ -637,7 +637,7 @@ internal static void GetBytes(in decimal d, Span<byte> buffer)

internal static decimal ToDecimal(ReadOnlySpan<byte> span)
{
Debug.Assert(span.Length >= 16, "span.Length >= 16");
Debug.Assert(span.Length >= 16);
int lo = BinaryPrimitives.ReadInt32LittleEndian(span);
int mid = BinaryPrimitives.ReadInt32LittleEndian(span.Slice(4));
int hi = BinaryPrimitives.ReadInt32LittleEndian(span.Slice(8));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ internal static StrongBidiCategory GetBidiCategory(string s, int index)

internal static StrongBidiCategory GetBidiCategory(StringBuilder s, int index)
{
Debug.Assert(s != null, "s != null");
Debug.Assert(s != null);
Debug.Assert(index >= 0 && index < s.Length, "index < s.Length");

// The logic below follows Table 3-5 in the Unicode Standard, Sec. 3.9.
Expand Down Expand Up @@ -363,7 +363,7 @@ public static UnicodeCategory GetUnicodeCategory(string s, int index)
internal static UnicodeCategory GetUnicodeCategoryInternal(string value, int index)
{
Debug.Assert(value != null, "value can not be null");
Debug.Assert(index < value.Length, "index < value.Length");
Debug.Assert(index < value.Length);

return GetUnicodeCategoryNoBoundsChecks((uint)GetCodePointFromString(value, index));
}
Expand All @@ -375,8 +375,8 @@ internal static UnicodeCategory GetUnicodeCategoryInternal(string value, int ind
internal static UnicodeCategory GetUnicodeCategoryInternal(string str, int index, out int charLength)
{
Debug.Assert(str != null, "str can not be null");
Debug.Assert(str.Length > 0, "str.Length > 0");
Debug.Assert(index >= 0 && index < str.Length, "index >= 0 && index < str.Length");
Debug.Assert(str.Length > 0);
Debug.Assert(index >= 0 && index < str.Length);

uint codePoint = (uint)GetCodePointFromString(str, index);
UnicodeDebug.AssertIsValidCodePoint(codePoint);
Expand Down Expand Up @@ -408,7 +408,7 @@ private static UnicodeCategory GetUnicodeCategoryNoBoundsChecks(uint codePoint)
/// </summary>
private static int GetCodePointFromString(string s, int index)
{
Debug.Assert(s != null, "s != null");
Debug.Assert(s != null);
Debug.Assert((uint)index < (uint)s.Length, "index < s.Length");

int codePoint = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ internal static int ParseRepeatPattern(ReadOnlySpan<char> format, int pos, char

private static string FormatDayOfWeek(int dayOfWeek, int repeat, DateTimeFormatInfo dtfi)
{
Debug.Assert(dayOfWeek >= 0 && dayOfWeek <= 6, "dayOfWeek >= 0 && dayOfWeek <= 6");
Debug.Assert(dayOfWeek >= 0 && dayOfWeek <= 6);
if (repeat == 3)
{
return dtfi.GetAbbreviatedDayName((DayOfWeek)dayOfWeek);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,8 @@ private static bool ParseTimeZone(ref __DTString str, scoped ref TimeSpan result
// Wrong number of digits
return false;
}
Debug.Assert(hourOffset >= 0 && hourOffset <= 99, "hourOffset >= 0 && hourOffset <= 99");
Debug.Assert(minuteOffset >= 0 && minuteOffset <= 99, "minuteOffset >= 0 && minuteOffset <= 99");
Debug.Assert(hourOffset >= 0 && hourOffset <= 99);
Debug.Assert(minuteOffset >= 0 && minuteOffset <= 99);
if (minuteOffset < 0 || minuteOffset >= 60)
{
return false;
Expand Down Expand Up @@ -2066,7 +2066,7 @@ private static bool GetTimeOfN(ref DateTimeResult result, scoped ref DateTimeRaw

private static bool GetTimeOfNN(ref DateTimeResult result, scoped ref DateTimeRawInfo raw)
{
Debug.Assert(raw.numCount >= 2, "raw.numCount >= 2");
Debug.Assert(raw.numCount >= 2);
if ((result.flags & ParseFlags.HaveTime) != 0)
{
// Multiple times in the input string
Expand All @@ -2088,7 +2088,7 @@ private static bool GetTimeOfNNN(ref DateTimeResult result, scoped ref DateTimeR
result.SetBadDateTimeFailure();
return false;
}
Debug.Assert(raw.numCount >= 3, "raw.numCount >= 3");
Debug.Assert(raw.numCount >= 3);
result.Hour = raw.GetNumber(0);
result.Minute = raw.GetNumber(1);
result.Second = raw.GetNumber(2);
Expand Down Expand Up @@ -2806,7 +2806,7 @@ private static bool DetermineTimeZoneAdjustments(ref DateTimeResult result, Date
else
{
// No time zone and no Assume flags, so DateTimeKind.Unspecified is fine
Debug.Assert(result.parsedDate.Kind == DateTimeKind.Unspecified, "result.parsedDate.Kind == DateTimeKind.Unspecified");
Debug.Assert(result.parsedDate.Kind == DateTimeKind.Unspecified);
return true;
}
}
Expand Down Expand Up @@ -3142,9 +3142,9 @@ internal static bool ParseDigits(ref __DTString str, int digitLen, out int resul

internal static bool ParseDigits(ref __DTString str, int minDigitLen, int maxDigitLen, out int result)
{
Debug.Assert(minDigitLen > 0, "minDigitLen > 0");
Debug.Assert(maxDigitLen < 9, "maxDigitLen < 9");
Debug.Assert(minDigitLen <= maxDigitLen, "minDigitLen <= maxDigitLen");
Debug.Assert(minDigitLen > 0);
Debug.Assert(maxDigitLen < 9);
Debug.Assert(minDigitLen <= maxDigitLen);
int localResult = 0;
int startingIndex = str.Index;
int tokenLength = 0;
Expand Down Expand Up @@ -5915,7 +5915,7 @@ internal DTSubString GetSubString()
return sub;
}
int number = ch - '0';
Debug.Assert(number >= 0 && number <= 9, "number >= 0 && number <= 9");
Debug.Assert(number >= 0 && number <= 9);
sub.value = sub.value * 10 + number;
}
else
Expand All @@ -5937,7 +5937,7 @@ internal DTSubString GetSubString()

internal void ConsumeSubString(DTSubString sub)
{
Debug.Assert(sub.index == Index, "sub.index == Index");
Debug.Assert(sub.index == Index);
Debug.Assert(sub.index + sub.length <= Length, "sub.index + sub.length <= len");
Index = sub.index + sub.length;
if (Index < Length)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public static int Compare(SortKey sortkey1, SortKey sortkey2)
byte[] key1Data = sortkey1._keyData;
byte[] key2Data = sortkey2._keyData;

Debug.Assert(key1Data != null, "key1Data != null");
Debug.Assert(key2Data != null, "key2Data != null");
Debug.Assert(key1Data != null);
Debug.Assert(key2Data != null);

// SortKey comparisons are done as an ordinal comparison by the raw sort key bytes.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ internal int InternalEmulateRead(int count)
if (n < 0)
n = 0;

Debug.Assert(_position + n >= 0, "_position + n >= 0"); // len is less than 2^31 -1.
Debug.Assert(_position + n >= 0); // len is less than 2^31 -1.
_position += n;
return n;
}
Expand Down Expand Up @@ -327,7 +327,7 @@ public override int Read(byte[] buffer, int offset, int count)
if (n <= 0)
return 0;

Debug.Assert(_position + n >= 0, "_position + n >= 0"); // len is less than 2^31 -1.
Debug.Assert(_position + n >= 0); // len is less than 2^31 -1.

if (n <= 8)
{
Expand Down Expand Up @@ -530,7 +530,7 @@ private long SeekCore(long offset, int loc)
throw new IOException(SR.IO_SeekBeforeBegin);
_position = tempPosition;

Debug.Assert(_position >= _origin, "_position >= _origin");
Debug.Assert(_position >= _origin);
return _position - _origin;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ internal static void FlushToDisk(SafeFileHandle handle)

internal static long Seek(SafeFileHandle handle, long offset, SeekOrigin origin, bool closeInvalidHandle = false)
{
Debug.Assert(origin >= SeekOrigin.Begin && origin <= SeekOrigin.End, "origin >= SeekOrigin.Begin && origin <= SeekOrigin.End");
Debug.Assert(origin >= SeekOrigin.Begin && origin <= SeekOrigin.End);

if (!Interop.Kernel32.SetFilePointerEx(handle, offset, out long ret, (uint)origin))
{
Expand Down Expand Up @@ -132,7 +132,7 @@ internal static void Unlock(SafeFileHandle handle, long position, long length)

internal static unsafe int ReadFileNative(SafeFileHandle handle, Span<byte> bytes, NativeOverlapped* overlapped, out int errorCode)
{
Debug.Assert(handle != null, "handle != null");
Debug.Assert(handle != null);

int r;
int numBytesRead = 0;
Expand Down
Loading
Loading