diff --git a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Boolean.cs b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Boolean.cs index fe1229852e231f..b19cee4e43ecc0 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Boolean.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Boolean.cs @@ -41,7 +41,7 @@ public static bool TryParse(ReadOnlySpan source, out bool value, out int b return true; } - if (4 < (uint)source.Length) + if (source.Length > 4) { if (dw == 0x534c4146 /* 'SLAF' */ && (source[4] & ~0x20) == 'E') { diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeFormat.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeFormat.cs index b1023765037a7f..8f4d8c4d749d6e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeFormat.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeFormat.cs @@ -1208,9 +1208,7 @@ private static bool TryFormatO(DateTime dateTime, TimeSpan offset, Span de // Tue, 03 Jan 2017 08:08:05 GMT private static bool TryFormatR(DateTime dateTime, TimeSpan offset, Span destination, out int charsWritten) { - // Writing the check in this fashion elides all bounds checks on 'destination' - // for the remainder of the method. - if (28 >= (uint)destination.Length) + if (destination.Length <= 28) { charsWritten = 0; return false; diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/EncoderFallback.cs b/src/libraries/System.Private.CoreLib/src/System/Text/EncoderFallback.cs index e1d60465765dba..0607dd6ce62350 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/EncoderFallback.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/EncoderFallback.cs @@ -134,7 +134,7 @@ private bool InternalFallback(ReadOnlySpan chars, out int charsConsumed) { firstChar = chars[0]; - if (1 < (uint)chars.Length) + if (chars.Length > 1) { secondChar = chars[1]; } diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/Rune.cs b/src/libraries/System.Private.CoreLib/src/System/Text/Rune.cs index d0ea9ae9322a55..7082e6656a37f6 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/Rune.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/Rune.cs @@ -316,7 +316,7 @@ public static OperationStatus DecodeFromUtf16(ReadOnlySpan source, out Run // Let's optimistically assume for now it's a high surrogate and hope // that combining it with the next char yields useful results. - if (1 < (uint)source.Length) + if (source.Length > 1) { char secondChar = source[1]; if (TryCreate(firstChar, secondChar, out result)) @@ -817,7 +817,7 @@ internal static int ReadFirstRuneFromUtf16Buffer(ReadOnlySpan input) // Treat 'returnValue' as the high surrogate. - if (1 >= (uint)input.Length) + if (input.Length <= 1) { return -1; // not an argument exception - just a "bad data" failure } diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf8.cs b/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf8.cs index 7444b3d6617acd..18a65596d07984 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf8.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf8.cs @@ -102,7 +102,7 @@ public static unsafe OperationStatus FromUtf16(ReadOnlySpan source, Span= (uint)destination.Length) + if (destination.Length <= 2) { operationStatus = OperationStatus.DestinationTooSmall; break;