diff options
author | Levi Broderick <levib@microsoft.com> | 2019-04-11 11:23:53 -0700 |
---|---|---|
committer | Levi Broderick <levib@microsoft.com> | 2019-04-11 11:24:20 -0700 |
commit | ce1310074786630235cc326e0438d2cf38b5aae6 (patch) | |
tree | 6ad7394127d21edc38dbf29178cc51f7ad27a1d7 | |
parent | 8f2860dc31227b4fa133480f54dd200640a170a4 (diff) | |
download | coreclr-ce1310074786630235cc326e0438d2cf38b5aae6.tar.gz coreclr-ce1310074786630235cc326e0438d2cf38b5aae6.tar.bz2 coreclr-ce1310074786630235cc326e0438d2cf38b5aae6.zip |
PR feedback: Validate nint definitions
4 files changed, 34 insertions, 0 deletions
diff --git a/src/System.Private.CoreLib/shared/System/Text/ASCIIUtility.cs b/src/System.Private.CoreLib/shared/System/Text/ASCIIUtility.cs index 18a668a099..8ff5b05429 100644 --- a/src/System.Private.CoreLib/shared/System/Text/ASCIIUtility.cs +++ b/src/System.Private.CoreLib/shared/System/Text/ASCIIUtility.cs @@ -21,6 +21,14 @@ namespace System.Text { internal static partial class ASCIIUtility { +#if DEBUG + static ASCIIUtility() + { + Debug.Assert(sizeof(nint) == IntPtr.Size && nint.MinValue < 0, "nint is defined incorrectly."); + Debug.Assert(sizeof(nuint) == IntPtr.Size && nuint.MinValue == 0, "nuint is defined incorrectly."); + } +#endif // DEBUG + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static bool AllBytesInUInt64AreAscii(ulong value) { diff --git a/src/System.Private.CoreLib/shared/System/Text/Unicode/Utf16Utility.Validation.cs b/src/System.Private.CoreLib/shared/System/Text/Unicode/Utf16Utility.Validation.cs index 878e593e3d..5f044b1543 100644 --- a/src/System.Private.CoreLib/shared/System/Text/Unicode/Utf16Utility.Validation.cs +++ b/src/System.Private.CoreLib/shared/System/Text/Unicode/Utf16Utility.Validation.cs @@ -20,6 +20,14 @@ namespace System.Text.Unicode { internal static unsafe partial class Utf16Utility { +#if DEBUG + static Utf16Utility() + { + Debug.Assert(sizeof(nint) == IntPtr.Size && nint.MinValue < 0, "nint is defined incorrectly."); + Debug.Assert(sizeof(nuint) == IntPtr.Size && nuint.MinValue == 0, "nuint is defined incorrectly."); + } +#endif // DEBUG + // Returns &inputBuffer[inputLength] if the input buffer is valid. /// <summary> /// Given an input buffer <paramref name="pInputBuffer"/> of char length <paramref name="inputLength"/>, diff --git a/src/System.Private.CoreLib/shared/System/Text/Unicode/Utf8Utility.Transcoding.cs b/src/System.Private.CoreLib/shared/System/Text/Unicode/Utf8Utility.Transcoding.cs index c160b1b580..9ee331ca11 100644 --- a/src/System.Private.CoreLib/shared/System/Text/Unicode/Utf8Utility.Transcoding.cs +++ b/src/System.Private.CoreLib/shared/System/Text/Unicode/Utf8Utility.Transcoding.cs @@ -22,6 +22,16 @@ namespace System.Text.Unicode { internal static unsafe partial class Utf8Utility { +#if DEBUG + static Utf8Utility() + { + Debug.Assert(sizeof(nint) == IntPtr.Size && nint.MinValue < 0, "nint is defined incorrectly."); + Debug.Assert(sizeof(nuint) == IntPtr.Size && nuint.MinValue == 0, "nuint is defined incorrectly."); + + _ValidateAdditionalNIntDefinitions(); + } +#endif // DEBUG + // On method return, pInputBufferRemaining and pOutputBufferRemaining will both point to where // the next byte would have been consumed from / the next char would have been written to. // inputLength in bytes, outputCharsRemaining in chars. diff --git a/src/System.Private.CoreLib/shared/System/Text/Unicode/Utf8Utility.Validation.cs b/src/System.Private.CoreLib/shared/System/Text/Unicode/Utf8Utility.Validation.cs index 8ef9369d3d..6425ae1da3 100644 --- a/src/System.Private.CoreLib/shared/System/Text/Unicode/Utf8Utility.Validation.cs +++ b/src/System.Private.CoreLib/shared/System/Text/Unicode/Utf8Utility.Validation.cs @@ -19,6 +19,14 @@ namespace System.Text.Unicode { internal static unsafe partial class Utf8Utility { +#if DEBUG + private static void _ValidateAdditionalNIntDefinitions() + { + Debug.Assert(sizeof(nint) == IntPtr.Size && nint.MinValue < 0, "nint is defined incorrectly."); + Debug.Assert(sizeof(nuint) == IntPtr.Size && nuint.MinValue == 0, "nuint is defined incorrectly."); + } +#endif // DEBUG + // Returns &inputBuffer[inputLength] if the input buffer is valid. /// <summary> /// Given an input buffer <paramref name="pInputBuffer"/> of byte length <paramref name="inputLength"/>, |