From ef4834be9469e08590ead851d77b237d530bb434 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 8 Aug 2022 15:45:23 +0200 Subject: [PATCH] Fix a StackOverflowException in some polyfills These APIs were never actually called by any code paths reachable by ComputeSharp (they're mostly there just to make porting polyfills easier), but still good to fix --- .../System/IntPtrExtensions.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/ComputeSharp.NetStandard/System/IntPtrExtensions.cs b/src/ComputeSharp.NetStandard/System/IntPtrExtensions.cs index 465f1ede..481b7b9c 100644 --- a/src/ComputeSharp.NetStandard/System/IntPtrExtensions.cs +++ b/src/ComputeSharp.NetStandard/System/IntPtrExtensions.cs @@ -9,15 +9,25 @@ internal static class IntPtrExtensions { /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int CompareTo(this nint left, nint right) + public static unsafe int CompareTo(this nint left, nint right) { - return left.CompareTo(right); + if (sizeof(nint) == sizeof(int)) + { + return ((int)left).CompareTo((int)right); + } + + return ((long)left).CompareTo(right); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int CompareTo(this nuint left, nuint right) + public static unsafe int CompareTo(this nuint left, nuint right) { - return left.CompareTo(right); + if (sizeof(nuint) == sizeof(uint)) + { + return ((uint)left).CompareTo((uint)right); + } + + return ((ulong)left).CompareTo(right); } } \ No newline at end of file