Fix filling across the end in PieceTableByteArrayModel & ByteArrayModel

parent 4827fc24
......@@ -327,7 +327,7 @@ Size ByteArrayModelPrivate::fill( Byte fillByte, Address offset, Size fillLength
return 0;
// nothing to fill
if( offset >= mSize )
if( (offset >= mSize) || (fillLength == 0) )
return 0;
const bool wasModifiedBefore = mModified;
......@@ -336,13 +336,24 @@ Size ByteArrayModelPrivate::fill( Byte fillByte, Address offset, Size fillLength
if( fillLength < 0 )
fillLength = lengthToEnd;
else if( fillLength > lengthToEnd )
fillLength = addSize( fillLength, offset, false );
const bool isToFillBehindEnd = ( fillLength > lengthToEnd );
const Size replacedLength = ( isToFillBehindEnd ? lengthToEnd : fillLength );
if( isToFillBehindEnd )
{
Size sizeToAdd = fillLength - lengthToEnd;
sizeToAdd = addSize( sizeToAdd, offset, false );
fillLength = lengthToEnd + sizeToAdd;
}
// nothing to fill
if( fillLength == 0 )
return 0;
memset( &mData[offset], fillByte, fillLength );
mModified = true;
emit p->contentsChanged( ArrayChangeMetricsList::oneReplacement(offset,fillLength,fillLength) );
emit p->contentsChanged( ArrayChangeMetricsList::oneReplacement(offset,replacedLength,fillLength) );
if( ! wasModifiedBefore )
emit p->modifiedChanged( true );
return fillLength;
......
......@@ -197,7 +197,7 @@ Size PieceTableByteArrayModelPrivate::fill( Byte fillByte, Address offset, Size
fillLength = lengthToEnd;
const int filledLength = ( fillLength < lengthToEnd ) ? fillLength : lengthToEnd;
// check parameters
const bool nothingToFill = ( (int)offset >= mPieceTable.size() );
const bool nothingToFill = ( ((int)offset >= mPieceTable.size()) || (fillLength == 0));
if( nothingToFill )
return 0;
......@@ -428,7 +428,7 @@ void PieceTableByteArrayModelPrivate::doFillChange( Address offset, Size filledL
mChangesDataStorage.appendFill( storageOffset, fillByte, fillLength );
const ArrayChangeMetrics metrics =
ArrayChangeMetrics::asReplacement( offset, fillLength, fillLength );
ArrayChangeMetrics::asReplacement( offset, filledLength, fillLength );
const ByteArrayChange change( metrics );
mChangeMetrics.append( metrics );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment