[Lazarus] EXC_BAD_ACCESS, Could not access memory

Roland Turcan konf at rotursoft.sk
Sat Apr 25 09:43:24 CEST 2009


Hello Diettrich,

To tell the truth this code and style I got from previous developer
and I really don't know why he decided to get the size of header from
the binary instead of getting its size. The fact is, that this
"optimistic variant" of coding is on many places. :-|

TRoland;

<<< 24.4.2009 19:56 - Hans-Peter Diettrich "DrDiettrich1 at aol.com" >>>
HPD> Roland Turcan schrieb:

>> BB> How is HeaderLen declared ?
>> 
>> Stream.Read (HeaderLen, SIZEOF (HeaderLen));
>> 
>> where information header's length is stored into binary.

HPD> The you should verify that HeaderLen <= SizeOf(FHeader), before
HPD>    Stream.Read (FHeader, HeaderLen);

HPD> Otherwise this statement will overwrite the following FItem data, with
HPD> the fatal consequences you already experienced.

HPD> When a header will ever change in size (or structure), it's wise to 
HPD> store a version number in the data files. Then you can read the stored
HPD> header data into the exactly applicable header type (record), and 
HPD> convert that record into the current THeader definition, field by field.

HPD> DoDi

HPD> _______________________________________________
HPD> Lazarus mailing list
HPD> Lazarus at lazarus.freepascal.org
HPD> http://www.lazarus.freepascal.org/mailman/listinfo/lazarus




-- 
Best regards, TRoland
http://www.rotursoft.sk
http://exekutor.rotursoft.sk




More information about the Lazarus mailing list