Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail if Append()ing string to Rope in excess of TInlineString size #155

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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