[fpc-pascal] Getmem -> Move -> Freemem

Marco van de Voort marcov at stack.nl
Sun Apr 26 18:46:27 CEST 2009


In our previous episode, Guillermo Martínez Jiménez said:
>   fSize := aObject^.size;
>   GetMem (fData, fSize);
>   Move (aObject^.dat, fData, fSize);
> 
> Both "fData" and "dat" are untyped POINTER but the program returns an
> "Segment violation" at the Move procedure. I've checked the pointers
> and both are valid (I mean not NIL) and size is always more than zero.

Both are .dat and fdata are points. IOW you are moving "fsize" bytes from
the place where the 4 byte of the pointer dat is stored to the place where
the 4 bytes of the pointer fdata is stored. Since you probably move more
than 4 bytes you totally corrupt what is behind "fdata" in memory.

Try  .dat^ and fdata^ in the move line.
 



More information about the fpc-pascal mailing list