[fpc-devel] move(xx, ansistring[1] versus ansistring, len)

Martin Friebe fpc at mfriebe.de
Mon May 12 23:27:08 CEST 2008


I am trying to find some info on how I can use move to archive the

I am looking for an equal replacement of
move(somepchar^, ansi_str_dest[1], len)

The problem with ansi_str_dest[1] is that if the above call happens with
a len of 0, and an ansi string with 0 length => this leads to a range
check exception.
  SetLength(as,0); copy(src^, as[1], 0);
Accessing the first of zero characters => range check.
( It will work without range-checking, since whatever address is
returned by [1] is never accessed )

I could prefix it with "if length(dest) > 0 then ", but I would prefer
something less noticeable...

I could do
  SetLength(as,0);  copy(src^, as, 0);
But from looking at the assembler produced during compilation, this does
not check for fpc_ansistr_unique. Same for any type casting to PChar.

Anyone any idea?


More information about the fpc-devel mailing list