SynEdit: Restore Copy() calls. SetLength() may make a string longer with garbage in the end.

git-svn-id: trunk@64730 -
This commit is contained in:
juha 2021-03-03 10:21:52 +00:00
parent d374ec2bf1
commit dfb8608d9a
4 changed files with 8 additions and 8 deletions

View File

@ -604,7 +604,7 @@ begin
dec(BackCounter);
Temp := GetLine(BackCounter);
if Temp <> '' then begin
SetLength(Temp, GetIndentForLine(FCurrentEditor, Temp, False));
Temp := copy(Temp, 1, GetIndentForLine(FCurrentEditor, Temp, False));
PhysLen := GetIndentForLine(FCurrentEditor, Temp, True);
if (PhysLen > KnownPhysLen) and StartsStr(BasedMix, Temp) then
begin
@ -714,7 +714,7 @@ begin
// Temp := Lines[FoundLine-1]
//else
// FoundLine := BackCounter + 1;
SetLength(Temp, GetIndentForLine(Editor, Temp, False));
Temp := copy(Temp, 1, GetIndentForLine(Editor, Temp, False));
case FIndentType of
sbitCopySpaceTab:

View File

@ -2713,7 +2713,7 @@ function TSynEditMarkupHighlightAllCaret.GetCurrentText: String;
Result := copy(s, i, MaxInt);
i := length(Result);
while (i > 0) and (Result[i] in [#1..#32]) do dec(i);
SetLength(Result, i);
Result := copy(Result, 1, i);
end;
var
LowBnd, UpBnd: TPoint;

View File

@ -596,7 +596,7 @@ begin
j := i - length(s) - 1;
s := copy(FSpaces, j + 1, MaxInt);
{$IFDEF SynTrimDebug}debugln(['--- Trimmer -- CaretChanged - Trimming,part to ',length(s),' ', ' fLineIndex=', fLineIndex, ' fSpaces=',length(fSpaces), 'newCaretYPos=',TSynEditCaret(Sender).LinePos]);{$ENDIF}
SetLength(FSpaces, j);
FSpaces := copy(FSpaces, 1, j);
i := length(s);
MaybeAddUndoForget(FLineIndex+1, s);
SendNotification(senrLineChange, self, fLineIndex, 1);
@ -1000,7 +1000,7 @@ begin
{$IFDEF SynTrimDebug}debugln(['--- Trimmer -- EditMoveToTrim()', ' fLineIndex=', fLineIndex, ' fSpaces=',length(fSpaces), ' Y=',LogY, ' len=',Len]);{$ENDIF}
t := NextLines[LogY - 1];
s := copy(t, 1 + length(t) - Len, Len) + Spaces(LogY - 1);
SetLength(t, length(t) - Len);
t := copy(t, 1, length(t) - Len);
StoreSpacesForLine(LogY - 1, s, t);
NextLines[LogY - 1] := t;
CurUndoList.AddChange(TSynEditUndoTrimMoveTo.Create(LogY, Len));
@ -1118,7 +1118,7 @@ begin
LenNS := LastNoneSpacePos(AText);
if LenNS < Len then begin
EditInsertTrim(1, LogY, copy(AText, 1 + LenNS, Len));
SetLength(AText, LenNS);
AText := copy(AText, 1, LenNS);
end;
end;
end;
@ -1276,7 +1276,7 @@ begin
LenNS := LastNoneSpacePos(AText);
if LenNS < Len then begin
EditInsertTrim(1, LogY, copy(AText, 1 + LenNS, Len));
SetLength(AText, LenNS);
AText := copy(AText, 1, LenNS);
end;
end;
end;

View File

@ -513,7 +513,7 @@ end;
function SizePxFromString(S: String): Integer;
begin
SetLength(S, PosI('px',S)-1);
S := Copy(S, 1, PosI('px',S)-1);
Result := StrToIntDef(S, 0);
end;