From 2c02de7cff8079a26afbd2457ff283c69a4af3e8 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 4 May 2024 12:31:29 -0700 Subject: [PATCH] Fix 'SByte' and 'Byte' cases --- .../src/System/InvokeUtils.cs | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/InvokeUtils.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/InvokeUtils.cs index 1d4007ac93a68a..88013f0ad58b0b 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/InvokeUtils.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/InvokeUtils.cs @@ -191,16 +191,26 @@ private static Exception ConvertOrWidenPrimitivesEnumsAndPointersIfPossible(obje break; case EETypeElementType.SByte: - - // Can only be sbyte here - sbyteValue = RuntimeHelpers.FastUnbox(srcObject); + switch (srcElementType) + { + case EETypeElementType.SByte: + sbyteValue = RuntimeHelpers.FastUnbox(srcObject); + break; + default: + goto Failure; + } rawDstValue = &sbyteValue; break; case EETypeElementType.Byte: - - // Can only be byte here - byteValue = RuntimeHelpers.FastUnbox(srcObject); + switch (srcElementType) + { + case EETypeElementType.Byte: + byteValue = RuntimeHelpers.FastUnbox(srcObject); + break; + default: + goto Failure; + } rawDstValue = &byteValue; break;