From 0501f61b9bd61bd0af43802cf6ae8478b4540e19 Mon Sep 17 00:00:00 2001 From: mattias Date: Sat, 20 Feb 2021 20:50:36 +0000 Subject: [PATCH] TMaskEdit: workaround for infinite loop in SetEditText (issue cause by compiler bug). Issue #0038505 git-svn-id: branches/fixes_2_0@64634 - --- lcl/maskedit.pp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/lcl/maskedit.pp b/lcl/maskedit.pp index 32f0b7d715..6c19757113 100644 --- a/lcl/maskedit.pp +++ b/lcl/maskedit.pp @@ -1124,8 +1124,10 @@ procedure TCustomMaskEdit.SetEditText(const AValue: string); //Note: This is not Delphi compatible, but by design //Delphi lets you just set EditText of any length, which is extremely dangerous! var - S: String; + S, OldS: String; i: Integer; + ULen: PtrInt; + ClearCh: TUTF8Char; begin if (not IsMasked) then begin @@ -1140,7 +1142,22 @@ begin for i := 1 to Utf8Length(S) do if IsLiteral(FMask[i]) then SetCodePoint(S,i,ClearChar(i)); //Pad resulting string with ClearChar if text is too short - while Utf8Length(S) < FMaskLength do S := S + ClearChar(Utf8Length(S)+1); + + //while Utf8Length(S) < FMaskLength do S := S + ClearChar(Utf8Length(S)+1); + //the above should work again after the release of fpc 3.2.2? + //for the time being do it like this: + while Utf8Length(S) < FMaskLength do + begin + //workaround for fpc issue #0038337 + //Utf8Length(S) corrupts S, so concatenation with ClearChar() fails, leading to an endless loop. + //See issue #0038505 + OldS := S; + ULen := Utf8Length(S); + ClearCh := ClearChar(Ulen+1); + //DbgOut(['TCustomMaskEdit.SetEditText: S="',S,'", Utf8Length(S)=',ULen,', FMaskLength=',FMaskLength,', ClearChar(',Ulen+1,')=',ClearCh]); + S := OldS + ClearCh; + //debugln(' --> S:',S); + end; RealSetTextWhileMasked(S); end; end;