Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2015-05

StrPLCopy with MaxLen=0

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

LacaK

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

Reply by email

Michael Van Canneyt
to LacaK
LacaK wrote 41 lines
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.

Reply by email

LacaK
to Michael Van Canneyt

Dňa 14.5.2015 o 14:15 Michael Van Canneyt napísal(a):

Show quoted text 52 lines
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.

Thanks
http://bugs.freepascal.org/view.php?id=28089

-Laco.

Reply by email