Skip to content

Commit fc787e4

Browse files
committed
Fix accessing a null element in a byref array
- Code now grabs element type from array instead of element when element is null.
1 parent 5f9d281 commit fc787e4

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/CLR/Core/TypeSystem.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2546,6 +2546,16 @@ HRESULT CLR_RT_TypeDescriptor::InitializeFromObject(const CLR_RT_HeapBlock &ref)
25462546
{
25472547
obj = (CLR_RT_HeapBlock *)array->GetElement(obj->ArrayIndex());
25482548

2549+
// For reference arrays, if the element is null, we need to get the type from the array's element
2550+
// type rather than trying to dereference a null object
2551+
if (obj->Dereference() == nullptr)
2552+
{
2553+
// Use the array's element type.
2554+
// Keep 'reflex' null to avoid carrying array levels when returning an element type.
2555+
cls = &(array->ReflectionDataConst().data.type);
2556+
break;
2557+
}
2558+
25492559
NANOCLR_SET_AND_LEAVE(InitializeFromObject(*obj));
25502560
}
25512561

0 commit comments

Comments
 (0)