View Issue Details

IDProjectCategoryView StatusLast Update
0038505LazarusLCLpublic2021-02-20 09:36
ReporterMarcou Gilles Assigned ToBart Broersma  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version2.0.10 
Summary0038505: MaskEdit.EditText infinite loop
DescriptionWhen a value is assigned to a MaskEdit using an EditText, it triggers an infinite loop.
Steps To ReproduceCreate a projet with a button that assigns a value to a MaskEdit component using the method EditText:

procedure TForm1.Button1Click(Sender: TObject);
begin
  MaskEdit1.EditText:='1';
end;

The EditMask is set to: 999999;1;_
Additional InformationThe infinite loop is located in the file maskedit.pp at line 1143:

while Utf8Length(S) < FMaskLength do S := S + ClearChar(Utf8Length(S)+1)

It continuously calls the ClearChar function.

System details:
 Operating System: Ubuntu 20.10
 Kernel: Linux 5.8.0-41-generic
 Architecture: x86-64
TagsNo tags attached.
Fixed in Revisionr64617, r64625
LazTarget-
WidgetsetGTK 2
Attached Files

Activities

Marcou Gilles

2021-02-18 09:50

reporter   ~0128991

Added a demo.
project1.lpr (387 bytes)   
program project1;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Interfaces, // this includes the LCL widgetset
  Forms, Unit1
  { you can add units after this };

{$R *.res}

begin
  RequireDerivedFormResource:=True;
  Application.Scaled:=True;
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.

project1.lpr (387 bytes)   
unit1.lfm (569 bytes)   
object Form1: TForm1
  Left = 246
  Height = 238
  Top = 170
  Width = 317
  Caption = 'Form1'
  ClientHeight = 238
  ClientWidth = 317
  DesignTimePPI = 95
  LCLVersion = '2.0.10.0'
  object MaskEdit1: TMaskEdit
    Left = 127
    Height = 26
    Top = 91
    Width = 79
    CharCase = ecNormal
    MaxLength = 6
    TabOrder = 0
    EditMask = '999999;1;_'
    Text = '      '
    SpaceChar = '_'
  end
  object Button1: TButton
    Left = 151
    Height = 25
    Top = 144
    Width = 74
    Caption = 'Button1'
    OnClick = Button1Click
    TabOrder = 1
  end
end
unit1.lfm (569 bytes)   
unit1.pas (449 bytes)   
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, MaskEdit, StdCtrls;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    MaskEdit1: TMaskEdit;
    procedure Button1Click(Sender: TObject);
  private

  public

  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
begin
  MaskEdit1.EditText:='1';
end;

end.

unit1.pas (449 bytes)   

Bart Broersma

2021-02-18 19:10

developer   ~0129001

Last edited: 2021-02-18 19:39

View 2 revisions

Most likely caused by fpc bug 0038337.
This leads to curruption of S.
In fact in the frist iteration of the loop S starts out as "1", but after ClearChar(2) is addes, S suddenly becomes "--". Note that the "1" has disappeared.
After that, all concatenations leave S being "--", hence the infinite loop.

If my analysis is correct then the issue should be resolve by fpc r48128 (which will be in 3.2.2).

Bart Broersma

2021-02-18 19:46

developer   ~0129002

Implemented a workaround.
Please test and close if OK.

Issue History

Date Modified Username Field Change
2021-02-18 00:51 Marcou Gilles New Issue
2021-02-18 09:50 Marcou Gilles Note Added: 0128991
2021-02-18 09:50 Marcou Gilles File Added: project1.lpr
2021-02-18 09:50 Marcou Gilles File Added: unit1.lfm
2021-02-18 09:50 Marcou Gilles File Added: unit1.pas
2021-02-18 18:36 Bart Broersma Assigned To => Bart Broersma
2021-02-18 18:36 Bart Broersma Status new => assigned
2021-02-18 18:36 Bart Broersma Status assigned => confirmed
2021-02-18 18:36 Bart Broersma LazTarget => -
2021-02-18 18:36 Bart Broersma Status confirmed => assigned
2021-02-18 19:10 Bart Broersma Note Added: 0129001
2021-02-18 19:39 Bart Broersma Note Edited: 0129001 View Revisions
2021-02-18 19:46 Bart Broersma Status assigned => resolved
2021-02-18 19:46 Bart Broersma Resolution open => fixed
2021-02-18 19:46 Bart Broersma Fixed in Revision => r64617
2021-02-18 19:46 Bart Broersma Widgetset GTK 2 => GTK 2
2021-02-18 19:46 Bart Broersma Note Added: 0129002
2021-02-20 09:36 Bart Broersma Fixed in Revision r64617 => r64617, r64625
2021-02-20 09:36 Bart Broersma Widgetset GTK 2 => GTK 2