Skip to content

Commit

Permalink
Fail if Append()ing string to Rope in excess of TInlineString size
Browse files Browse the repository at this point in the history
Relates to #153
  • Loading branch information
sideshowbarker committed Aug 8, 2023
1 parent 4cabebb commit 5f649bc
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/lib/ropes.pas
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ TFixedSizeRopeFragment = record
TUTF8InlineIndexPlusOne = 0..UTF8InlineSize;
TCodepointsIndex = 0..CodepointsSize-1;
TCodepointsIndexPlusOne = 0..CodepointsSize;
TInlineString = String[UTF8InlineSize];
TInlineString = String[UTF8InlineSize + 1];
PRopeFragment = ^TRopeFragment;
TRopeFragment = record
Next: PRopeFragment;
Expand Down Expand Up @@ -963,6 +963,12 @@ 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: Append() call with string length > UTF8InlineSize: "' + NewString + '"');
Writeln('Call Append() with a string pointer, not a string: Append(@Foo), not Append(Foo)');
Halt(1);
end;
if ((not Assigned(FLast)) or (FLast^.Kind <> rfUTF8Inline) or (RopeInternals.UTF8InlineSize - FLast^.InlineLength < Length(NewString))) then
begin
EnsureSize(1, 1);
Expand Down

0 comments on commit 5f649bc

Please sign in to comment.