浏览代码

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

git-svn-id: trunk@30858 -
Jonas Maebe 10 年之前
父节点
当前提交
afd5ed4afe
共有 3 个文件被更改,包括 24 次插入7 次删除
  1. 1 0
      .gitattributes
  2. 6 7
      rtl/objpas/sysutils/syspch.inc
  3. 17 0
      tests/webtbs/tw28089.pp

+ 1 - 0
.gitattributes

@@ -14487,6 +14487,7 @@ tests/webtbs/tw28007.pp svneol=native#text/pascal
 tests/webtbs/tw2803.pp svneol=native#text/plain
 tests/webtbs/tw2803.pp svneol=native#text/plain
 tests/webtbs/tw2806.pp svneol=native#text/plain
 tests/webtbs/tw2806.pp svneol=native#text/plain
 tests/webtbs/tw2807.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/tw2809.pp svneol=native#text/plain
 tests/webtbs/tw2812.pp svneol=native#text/plain
 tests/webtbs/tw2812.pp svneol=native#text/plain
 tests/webtbs/tw2815.pp svneol=native#text/plain
 tests/webtbs/tw2815.pp svneol=native#text/plain

+ 6 - 7
rtl/objpas/sysutils/syspch.inc

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

+ 17 - 0
tests/webtbs/tw28089.pp

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