From bd4c60a251626d3c8ec9cbe5c9da84f0b3c18398 Mon Sep 17 00:00:00 2001 From: xposure Date: Mon, 4 Jan 2021 20:40:03 -0500 Subject: [PATCH 1/3] fixed crash with CreateObject on ArrayType when count is 0 --- BeefLibs/corlib/src/Type.bf | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/BeefLibs/corlib/src/Type.bf b/BeefLibs/corlib/src/Type.bf index 3ae02343..ad12ed4e 100644 --- a/BeefLibs/corlib/src/Type.bf +++ b/BeefLibs/corlib/src/Type.bf @@ -1120,7 +1120,8 @@ namespace System.Reflection obj = Internal.UnsafeCastToObject(mem); obj.[Friend]mClassVData = (.)(void*)[Friend]mTypeClassVData; #endif - Internal.MemSet((uint8*)Internal.UnsafeCastToPtr(obj) + [Friend]mInstSize, 0, [Friend]arraySize - [Friend]mInstSize); + if(count > 0) + Internal.MemSet((uint8*)Internal.UnsafeCastToPtr(obj) + [Friend]mInstSize, 0, [Friend]arraySize - [Friend]mInstSize); var array = (Array)obj; array.[Friend]mLength = count; return obj; From f606006c3956f8f99efd81c62de7560b78f52e81 Mon Sep 17 00:00:00 2001 From: xposure Date: Mon, 4 Jan 2021 20:42:04 -0500 Subject: [PATCH 2/3] fixing the fix, we only need to memset when count is > 1 because Array1 holds the first element --- BeefLibs/corlib/src/Type.bf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BeefLibs/corlib/src/Type.bf b/BeefLibs/corlib/src/Type.bf index ad12ed4e..c32bb5c7 100644 --- a/BeefLibs/corlib/src/Type.bf +++ b/BeefLibs/corlib/src/Type.bf @@ -1120,7 +1120,7 @@ namespace System.Reflection obj = Internal.UnsafeCastToObject(mem); obj.[Friend]mClassVData = (.)(void*)[Friend]mTypeClassVData; #endif - if(count > 0) + if(count > 1) Internal.MemSet((uint8*)Internal.UnsafeCastToPtr(obj) + [Friend]mInstSize, 0, [Friend]arraySize - [Friend]mInstSize); var array = (Array)obj; array.[Friend]mLength = count; From 2cfcfd911382d278ada4cab9e0edef44d4485e80 Mon Sep 17 00:00:00 2001 From: xposure Date: Mon, 4 Jan 2021 20:43:03 -0500 Subject: [PATCH 3/3] adding comment on ArrayType CreateObject for count > 1 --- BeefLibs/corlib/src/Type.bf | 1 + 1 file changed, 1 insertion(+) diff --git a/BeefLibs/corlib/src/Type.bf b/BeefLibs/corlib/src/Type.bf index c32bb5c7..db556780 100644 --- a/BeefLibs/corlib/src/Type.bf +++ b/BeefLibs/corlib/src/Type.bf @@ -1120,6 +1120,7 @@ namespace System.Reflection obj = Internal.UnsafeCastToObject(mem); obj.[Friend]mClassVData = (.)(void*)[Friend]mTypeClassVData; #endif + //Array1 holds the first element, we only want to set the remaining elements if(count > 1) Internal.MemSet((uint8*)Internal.UnsafeCastToPtr(obj) + [Friend]mInstSize, 0, [Friend]arraySize - [Friend]mInstSize); var array = (Array)obj;