So, we recently updated to XE3 at work (began transition before XE4)... and today one of our customers ran across this code-gen bug, which causes an AV due to nil pointer access. Took some time to find it since we of course mostly run Debug builds on our dev machines, so couldn't reproduce the AV right away.
So, we recently updated to XE3 at work (began transition before XE4)... and today one of our customers ran across this code-gen bug, which causes an AV due to nil pointer access. Took some time to find it since we of course mostly run Debug builds on our dev machines, so couldn't reproduce the AV right away.
{$O+}
procedure TForm1.Button1Click(Sender: TObject);
var
lValue: string;
begin
lValue:='X';
if not cds1.IsEmpty and (lValue='D') then
//if (lValue='D') and not cds1.IsEmpty then //<---this line works
cds1.Delete
else if not cds1.IsEmpty then
cds1.Edit
else
cds1.Append;
end;
"cds1" here is a TClientDataSet with a single field. It crashes on the Edit or Append.
Disabling optimizations works, as does rearranging the "and" expression.
Wonder how this slipped past unit testing.
{$O+}
procedure TForm1.Button1Click(Sender: TObject);
var
lValue: string;
begin
lValue:='X';
if not cds1.IsEmpty and (lValue='D') then
//if (lValue='D') and not cds1.IsEmpty then //<---this line works
cds1.Delete
else if not cds1.IsEmpty then
cds1.Edit
else
cds1.Append;
end;
"cds1" here is a TClientDataSet with a single field. It crashes on the Edit or Append.
Disabling optimizations works, as does rearranging the "and" expression.
Wonder how this slipped past unit testing.
Asbjørn Heid I would have been surprised if it were caught! It's not one of those things you'd generally expect to fail :)
ReplyDeleteA
Look if this synthax works:
ReplyDeleteif (not cds1.IsEmpty) and (lValue='D') then
MB
Marcin Barański Not in the test app we wrote :( Using XE3 Update 2.
ReplyDeleteSeems the issue is that it loads the address of "cds1" into a register (ESI here) on the Delete line, and then thinks this register is valid when it calls Edit or Append, using it to initialize EAX before the method calls.
Andrea Raimondi Well this is the compiler, they should test all the things that just should work ;)
ReplyDeleteXE4 Update1 still has that bug
ReplyDeleteStefan Glienke Thanks for checking. Not sure we'll jump to XE4 or 5 anytime soon anyway, components makes it a drag :(
ReplyDeleteYou should fill a QC report with that bug. Don't forget to add complete code to reproduce the error easily.
ReplyDeleteMy coworker said he had sent it to emb. I'll ask if he meant qc or direct mail (good a time as any to use one of our SA support incidents I guess).
ReplyDeletePost the QC link if possible.
ReplyDeleteHe reported it directly, so it's now internally tracked. I guess I can still make a QC out of it and mention this?
ReplyDelete