Skip to content

[Patch] Fix crash in MaskUtils FormatMaskText if Value is empty string

The following example crashes:

uses
  maskutils;

var
  Value, EditMask, Res: String;
begin
  Value := '';
  EditMask := '#-###-###-##-##;0;_';
  Res := FormatMaskText(EditMask, Value);
  writeln('Res = "',Res,'"');
end.

This is because in TMaskUtils.ApplyMaskToText Value[1] (and Value[0]) is accessed in the loop before there is a length check.

Reported on the forum: https://forum.lazarus.freepascal.org/index.php/topic,60803.0.html

Attached patch fixes the issue. maskutils.diff

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information