Fix self-overwrite in C4ValueArray::SetSlice (#1212: Array manipulation goes wrong )

issue1247
Julius Michaelis 2015-01-09 15:06:10 +09:00
parent 1213a2eef5
commit 8e7001ba0f
1 changed files with 4 additions and 1 deletions

View File

@ -347,7 +347,10 @@ void C4ValueArray::SetSlice(int32_t startIndex, int32_t endIndex, const C4Value
}
// Copy the data
for(i = startIndex, j = 0; i < iNewEnd; ++i, ++j)
// Since pnData and pData can be the same, we can not copy with
//for(i = startIndex, j = 0; i < iNewEnd; ++i, ++j)
// but have to start from the end of the copied sequence. That works, since j <= i
for(i = iNewEnd - 1, j = iNewEnd - startIndex - 1; i >= startIndex; --i, --j)
{
assert(j < iOtherSize);
pnData[i] = Other.pData[j];