diff --git a/src/lib/ropes.pas b/src/lib/ropes.pas index f6d375e..04da8e4 100644 --- a/src/lib/ropes.pas +++ b/src/lib/ropes.pas @@ -41,14 +41,14 @@ TFixedSizeRopeFragment = record private const FragmentPayloadSize = SizeOf(TFixedSizeRopeFragment); - UTF8InlineSize = 255; + UTF8InlineSize = 30; CodepointsSize = (FragmentPayloadSize-SizeOf(Byte)) div SizeOf(TUnicodeCodepoint); type TUTF8InlineIndex = 0..UTF8InlineSize-1; TUTF8InlineIndexPlusOne = 0..UTF8InlineSize; TCodepointsIndex = 0..CodepointsSize-1; TCodepointsIndexPlusOne = 0..CodepointsSize; - TInlineString = String[UTF8InlineSize]; + TInlineString = String[UTF8InlineSize + 1]; PRopeFragment = ^TRopeFragment; TRopeFragment = record Next: PRopeFragment; @@ -963,6 +963,11 @@ procedure Rope.Append(const NewString: RopeInternals.TInlineString); {$IFDEF VERBOSE} if (DebugNow) then Writeln('Ropes: Append(ShortString) on rope @', IntToHex(PtrUInt(@Self), 16), ' with data @', IntToHex(PtrUInt(FValue), 16)); {$ENDIF} {$IFDEF VERBOSE} if (DebugNow) then Writeln('Ropes: Length(FValue)=', Length(FValue)); {$ENDIF} Assert(Length(NewString) <= RopeInternals.UTF8InlineSize, 'Maximum size of short string is ' + IntToStr(RopeInternals.UTF8InlineSize)); + if (Length(NewString) > RopeInternals.UTF8InlineSize) then + begin + Writeln('Error: Operation attempted with string length > UTF8InlineSize: "' + NewString + '..."'); + Halt(1); + end; if ((not Assigned(FLast)) or (FLast^.Kind <> rfUTF8Inline) or (RopeInternals.UTF8InlineSize - FLast^.InlineLength < Length(NewString))) then begin EnsureSize(1, 1);