Browse Source

* fixed a couple of broken generic routines

florian 21 years ago
parent
commit
0b8ffc2fb2
1 changed files with 21 additions and 33 deletions
  1. 21 33
      rtl/inc/generic.inc

+ 21 - 33
rtl/inc/generic.inc

@@ -31,8 +31,16 @@ var
 begin
 begin
   if count <= 0 then exit;
   if count <= 0 then exit;
   Dec(count);
   Dec(count);
-  for i:=0 to count do
-    bytearray(dest)[i]:=bytearray(source)[i];
+  if @source<@dest then
+    begin
+      for i:=count downto 0 do
+        bytearray(dest)[i]:=bytearray(source)[i];
+    end
+  else
+    begin
+      for i:=0 to count do
+        bytearray(dest)[i]:=bytearray(source)[i];
+    end;
 end;
 end;
 {$endif not FPC_SYSTEM_HAS_MOVE}
 {$endif not FPC_SYSTEM_HAS_MOVE}
 
 
@@ -511,22 +519,12 @@ function fpc_shortstr_to_shortstr(len:longint;const sstr:shortstring): shortstri
 var
 var
   slen : byte;
   slen : byte;
 begin
 begin
-{ these are shortstrings, not pointers! (JM)
-  if dstr=nil then
-    exit;
-  if sstr=nil then
-    begin
-      if dstr<>nil then
-        pstring(dstr)^[0]:=#0;
-      exit;
-    end;
-}
   slen:=length(sstr);
   slen:=length(sstr);
   if slen<len then
   if slen<len then
     len:=slen;
     len:=slen;
-  { don't forget the length character }
-  if len <> 0 then
-    move(sstr[0],result[0],len+1);
+  move(sstr[0],result[0],len+1);
+  if slen>len then
+    result[0]:=chr(len);
 end;
 end;
 
 
 {$ifdef interncopy}
 {$ifdef interncopy}
@@ -539,25 +537,12 @@ var
 type
 type
   pstring = ^string;
   pstring = ^string;
 begin
 begin
-{ these are shortstrings, not pointers! (JM)
-  if dstr=nil then
-    exit;
-  if sstr=nil then
-    begin
-      if dstr<>nil then
-        pstring(dstr)^[0]:=#0;
-      exit;
-    end;
-}
   slen:=length(pstring(sstr)^);
   slen:=length(pstring(sstr)^);
   if slen<len then
   if slen<len then
     len:=slen;
     len:=slen;
-  { don't forget the length character }
-  if len <> 0 then
-      move(sstr^,dstr^,len+1);
- { already done by the move above (JM)
-  pstring(dstr)^[0]:=chr(len);
- }
+  move(sstr^,dstr^,len+1);
+  if slen>len then
+    pchar(dstr)^:=chr(len);
 end;
 end;
 
 
 {$endif ndef FPC_SYSTEM_HAS_FPC_SHORTSTR_ASSIGN}
 {$endif ndef FPC_SYSTEM_HAS_FPC_SHORTSTR_ASSIGN}
@@ -1134,7 +1119,10 @@ end;
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.66  2004-01-21 01:25:02  florian
+  Revision 1.67  2004-01-28 17:02:13  florian
+    * fixed a couple of broken generic routines
+
+  Revision 1.66  2004/01/21 01:25:02  florian
     * improved generic int. div routines
     * improved generic int. div routines
 
 
   Revision 1.65  2004/01/20 23:16:56  florian
   Revision 1.65  2004/01/20 23:16:56  florian
@@ -1296,4 +1284,4 @@ end;
       instead of direct comparisons of low/high values of orddefs because
       instead of direct comparisons of low/high values of orddefs because
       qword is a special case
       qword is a special case
 
 
-}
+}