[fpc-devel] StrPLCopy with MaxLen=0

Michael Van Canneyt michael at freepascal.org
Thu May 14 14:15:36 CEST 2015



On Thu, 14 May 2015, LacaK wrote:

> Hi,
>
> When I run this simple program in Delphi:
>
> ============================================
> program bug_StrPLCopy;
>
> {$APPTYPE CONSOLE}
>
> uses
>  SysUtils;
>
> var
>  Buf: array[0..10] of Char;
>
> begin
>  Buf[0] := 'A';
>  writeln(ord(Buf[0]));
>  StrPLCopy(Buf, '', 0);
>  writeln(ord(Buf[0]));
>  readln;
> end.
>
> ============================================
> Delphi Output is:
> 65
> 0
>
> In FPC Output is:
> 65
> 65
>
> So for MaxLen = 0 nothing happens.
>
> In function StrPLCopy there is:
>  if (Result <> Nil) and (MaxLen <> 0) then
>    ...
>
> Is it bug?

>From the delphi docs:

StrPLCopy copies up to a maximum of MaxLen characters from Source to the null-terminated string Dest. StrPLCopy returns a pointer to Dest.
     Note: Dest should point to a location with room for MaxLen + 1 characters, including the null terminator.

So: yes, it is a bug, please report it.

Michael.



More information about the fpc-devel mailing list