I *am* checking sizes before the move, which is why it surprised me that things were going out of bounds -- the trouble is I forgot the array index [0]
On Sat 24 Apr 2010, Martin wrote: > On 24/04/2010 22:01, Andrew Brunner wrote: > > David, > > > > I don't see how you are not getting memory leaks by doing a move > > before making sure that the destination buffer has the memory > > allocated. You see, in Delphi and FPC, move d/n actually move the > > memory... It just copies it. > > > > You were warned :-) > > > > On Sat, Apr 24, 2010 at 3:01 PM, David Emerson<dle...@angelbase.com> wrote: > > > >> cobines wrote: > >> > >>> David Emerson wrote: > >>> > >>>> move (src.f_data, self.f_data, length(self.f_data) * sizeof(byte)); > >>>> > >>> I think it should be: > >>> > >>> SetLength(self.f_data, length(src.f_data)); > >>> move (src.f_data[0], self.f_data[0], length(self.f_data) * sizeof(byte)); > >>> > >> > No he doesn't get leaks. If at all he would get crashes, by overwriting > random memory. > > But in this case, it's (almost !) save. > He uses " length(self.f_data)* sizeof(byte)" => so he never copies, more > bytes to the target than the target can hold. > > He may however copy bytes from behind the source, reading random memory > behind the source. He does not modify this random memory, so far so good > => as long as the random meory behind the source is accesible to his > process. If it's not accessible, then access violation. > > Martin > _______________________________________________ > fpc-pascal maillist - fpc-pascal@lists.freepascal.org > http://lists.freepascal.org/mailman/listinfo/fpc-pascal > _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal