Recent

Author Topic: Bugfix/Code Adjustment for TBinaryObjectReader  (Read 4158 times)

SiMozzer

  • Newbie
  • Posts: 1
Bugfix/Code Adjustment for TBinaryObjectReader
« on: August 19, 2004, 12:32:55 am »
Folks,

I've just started to use and appreciate FPC & Lazarus and have found a small bug in TBinaryObjectReader.  

The bug can be reproduced by creating a TReader with::

 TReader.Create(nil,BUFF_SIZE); { <- It is 'legal' to create a Tfiler assigned to a 'nil' stream
                                                       but maybe a bit stupid )
  try
    ///... more code
  finally
     TReader.Free; // <- This line will cause an access violation
  end;

 The code crashes because the internal TBinaryObjectReader attempts to access the stream in its destrucrtor without first testing if it is assigned. The following adjustment prevents the GPF ::

destructor TBinaryObjectReader.Destroy;
begin
  If Assigned(FStream) then  //<--- **test added here**
    { Seek back the amount of bytes that we didn't process until now: }
    FStream.Seek(Integer(FBufPos) - Integer(FBufEnd), soFromCurrent);

  if Assigned(FBuffer) then
    FreeMem(FBuffer, FBufSize);

  inherited Destroy;
end;

what are your thoughts?

R.E.S.P.E.C.T (jus like Franklin))

Si Mozzer

Anonymous

  • Guest
Bugfix/Code Adjustment for TBinaryObjectReader
« Reply #1 on: October 15, 2004, 12:44:01 am »
What Can I think :) - happy bug hunter
should submit a bugfix to merge into code...