* fixed StrPLCopy() with maxlen=0 (mantis #28089, patch by LacaK)

git-svn-id: trunk@30858 -
This commit is contained in:
Jonas Maebe 2015-05-15 09:00:56 +00:00
parent ac592ed634
commit afd5ed4afe
3 changed files with 24 additions and 7 deletions

1
.gitattributes vendored
View File

@ -14487,6 +14487,7 @@ tests/webtbs/tw28007.pp svneol=native#text/pascal
tests/webtbs/tw2803.pp svneol=native#text/plain
tests/webtbs/tw2806.pp svneol=native#text/plain
tests/webtbs/tw2807.pp svneol=native#text/plain
tests/webtbs/tw28089.pp svneol=native#text/plain
tests/webtbs/tw2809.pp svneol=native#text/plain
tests/webtbs/tw2812.pp svneol=native#text/plain
tests/webtbs/tw2815.pp svneol=native#text/plain

View File

@ -78,18 +78,17 @@ end ;
function StrPLCopy(Dest: PChar; Const Source: string; MaxLen: SizeUInt): PChar;overload;
var Count: SizeUInt;
begin
result := Dest;
if (Result <> Nil) and (MaxLen <> 0) then
Result := Dest;
if Result <> Nil then
begin
Count := Length(Source);
if Count > MaxLen then
Count := MaxLen;
StrMove(Dest, PChar(Source), Count);
result[Count] := #0; { terminate ! }
StrMove(Result, PChar(Source), Count);
Result[Count] := #0; { terminate ! }
end;
end;
{ StrDispose clears the memory allocated with StrAlloc }
procedure StrDispose(Str: PChar);

17
tests/webtbs/tw28089.pp Normal file
View File

@ -0,0 +1,17 @@
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.