[fpc-devel] Copy function and dynamic array
Ludo Brands
ludo.brands at free.fr
Wed Feb 29 14:22:44 CET 2012
> > Delphi documentation says:
> > "If Index is larger than the length of S, Copy returns an
> empty string
> > or array." http://docwiki.embarcadero.com/VCL/en/System.Copy
> >
> > Can it be fixed also in FPC?
>
> I think it's a Delphi bug to act like that. You must provide
> a length that is not bigger in size. It's up to you the
> developer. Otherwise you might have more then one type of
> buffer overflows in your code !
>
> The way Delphi solved it, is by taking the responsibility
> from the developer, and made the code a bit slower. And as I
> said, I don't think it's a good idea
>
In the mean time there is tons of code that relies on copy() copying until
end of string or dynamic array. Constructions like
param=copy(s,pos('=')+1,length(s)) are plenty. Just do a grep in the fpc
compiler dir for "copy(" and you'l find plenty of copy(s,p+1,255) and the
like.
Ludo
More information about the fpc-devel
mailing list