Problem in function TCustomBufDataset.DoApplyUpdate
I found a potential bug in function TCustomBufDataset.DoApplyUpdate. The result of the function is not fully initialized. Because of this, the HadError field may have a random value, which will result in an Access Violation error in an application that uses data access components. That's exactly what happened in my app until I figured out what was going on. It is noteworthy that the error occurs in a 64-bit Linux application, but there is no such error in a 32-bit Windows application. When I explicitly initialized the HadError field, the error no longer occurs.
function TCustomBufDataset.DoApplyUpdate(var aUpdate : TRecUpdateBuffer; AbortOnError : Boolean): TApplyRecUpdateResult;
Const
ErrorResponse : Array[Boolean] of TResolverResponse = (rrSkip,rrAbort);
begin
Result.Async:=False;
Result.Response:=rrApply;
Result.HadError:=False; // Initialize HadError so that there is no error.
// If the record is first inserted and afterwards deleted, do nothing
if ((aUpdate.UpdateKind=ukDelete) and not (assigned(aUpdate.OldValuesBuffer))) then
exit; // Now everything will be fine, because we initialized the HadError field.
try
PrepareForUpdate(aUpdate);
Result:=ApplyRecUpdateEx(aUpdate.UpdateKind);
except
on E: EDatabaseError do
begin
Result.Response:=ErrorResponse[AbortOnError];
Result.HadError:=True;
if HandleUpdateError(aUpdate,Result,E) then
DoApplyUpdate(aUpdate,AbortOnError)
else
raise;
end;
end;
end;
Lazarus 4.3 (rev lazarus_4_2-26-g44b59001af) FPC 3.2.3 x86_64-linux-gtk2
Edited by Pavel Duborkin