Forum > General

Access Violation in MaskUtils.FormatMaskText

(1/2) > >>

dmitryb:
Hello

Lazarus 2.2.2 (rev lazarus_2_2_2-0-g537f43754c) FPC 3.2.2 x86_64-win64-win32/win64

When I call the next code


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button2Click(Sender: TObject);var  EditMask: String;  Result: String;begin  EditMask := '#-###-###-##-##;0;_';  Result := MaskUtils.FormatMaskText(EditMask, '');end;
I got an Access Violation in
function TMaskUtils.ApplyMaskToText(AValue: String): String;

I can't figure out if this is a feature or a bug.

dje:
Looks like a bug to me around line 791 (MaskUtils.pas)
Code in question is:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---      //fill text from left to rigth, skipping MaskLiterals      j := 1;      for i := 1 to FMaskLength do      begin        if not IsLiteral(FMask[i]) then        begin          if (AValue[j] = #32) then S[i]:= FSpaceChar else S[i] := AValue[j];  // <<< ERROR HERE          Inc(j);          if j > Length(AValue) then Break;        end;      end; There is no check to see if AValue has zero length. The only check comes after Inc(J), which then breaks out the loop. There is some code below this that also doesn't check AValue for an EmptyStr.

Adding a length check fixes the issue. (Near the start of the function TMaskUtils.ApplyMaskToText)


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  for I := 1 To FMaskLength do  S := S + ClearChar(I);  if Length(AValue) > 0 then // <<<< New Code here  if FMaskSave then    

Bart:
FWIW: the similar function in Lazarus' MasEdit unit returns " -   -   -  -  " (without the quotes of course).

And that is because GetCodePoint() returns '' if index is out of bounds, so it kind of works by accident there.

Bart

Bart:
Reported and attached a patch in the bugtracker.

Bart

Bart:
And applied in #e736011c.

Bart

Navigation

[0] Message Index

[#] Next page

Go to full version