Skip to content

Commit 0516bd1

Browse files
authored
Fix String.Concat with arrays containing null elements (#3031)
1 parent 95a9516 commit 0516bd1

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

src/CLR/CorLib/corlib_native_System_String.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//
1+
//
22
// Copyright (c) .NET Foundation and Contributors
33
// Portions Copyright (c) Microsoft Corporation. All rights reserved.
44
// See LICENSE file in the project root for full license information.
@@ -1157,23 +1157,24 @@ HRESULT Library_corlib_native_System_String::Concat(CLR_RT_StackFrame &stack, CL
11571157

11581158
for (int iStr = 0; iStr < num; iStr++)
11591159
{
1160-
_ASSERTE(ptrSrc->DataType() == DATATYPE_OBJECT);
1161-
_ASSERTE(FIMPLIES(ptrSrc->Dereference(), ptrSrc->Dereference()->DataType() == DATATYPE_STRING));
1162-
1163-
szTextSrc = ptrSrc->RecoverString();
1164-
if (szTextSrc)
1160+
if (ptrSrc->Dereference() != NULL && ptrSrc->Dereference()->DataType() == DATATYPE_STRING)
11651161
{
1166-
len = (CLR_UINT32)hal_strlen_s(szTextSrc);
1162+
szTextSrc = ptrSrc->RecoverString();
11671163

1168-
if (i == 0)
1169-
{
1170-
totLen += len;
1171-
}
1172-
else
1164+
if (szTextSrc)
11731165
{
1174-
memcpy(szTextDst, szTextSrc, len);
1166+
len = (CLR_UINT32)hal_strlen_s(szTextSrc);
11751167

1176-
szTextDst += len;
1168+
if (i == 0)
1169+
{
1170+
totLen += len;
1171+
}
1172+
else
1173+
{
1174+
memcpy(szTextDst, szTextSrc, len);
1175+
1176+
szTextDst += len;
1177+
}
11771178
}
11781179
}
11791180

0 commit comments

Comments
 (0)