[fpc-devel] Copy function and dynamic array

Hans-Peter Diettrich DrDiettrich1 at aol.com
Wed Feb 29 17:09:19 CET 2012


ik schrieb:

> 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.

Delphi specified Copy as *not* requiring exact parameters. The length 
always could be bigger than the string length, in which case the copy 
stops at the end of the source string. Likewise the starting index can 
be past the length of the source string, resulting in an empty string.

Performance is not affected, and the overall code size decreases, when 
the user doesn't have to calculate and check everything, every time 
before calling Copy. Please understand that even throwing an exception 
requires an check before, so that it's only a simple decision whether to 
fix an improper parameter value silently, or to throw an exception.

DoDi




More information about the fpc-devel mailing list