* synchronised code of fpc_ansistr_to_chararray() with

fpc_shortstr_to_chararray()
  * same for fpc_unicodestr_to_chararray() + fixes

git-svn-id: branches/jvmbackend@18702 -
This commit is contained in:
Jonas Maebe 2011-08-20 08:26:00 +00:00
parent 02f443ce68
commit 1ac7146182
2 changed files with 16 additions and 14 deletions

View File

@ -301,16 +301,16 @@ end;
procedure fpc_ansistr_to_chararray(out res: array of ansichar; const src: ansistring); compilerproc;
var
i, len: SizeInt;
len: longint;
begin
len := length(src);
if len > length(res) then
len := length(res);
len:=length(src);
if len>length(res) then
len:=length(res);
{ make sure we don't try to access element 1 of the ansistring if it's nil }
if len > 0 then
if len>0 then
JLSystem.ArrayCopy(JLObject(AnsistringClass(src).fdata),0,JLObject(@res),0,len);
for i:=len to length(res) do
res[i]:=#0;
if len<=high(res) then
JUArrays.fill(TJByteArray(@res),len,high(res),0);
end;

View File

@ -422,19 +422,21 @@ end;
procedure fpc_unicodestr_to_chararray(out res: array of AnsiChar; const src: UnicodeString); compilerproc;
var
i, len: SizeInt;
len: longint;
temp: array of jbyte;
begin
len := length(src);
len:=length(src);
{ make sure we don't dereference src if it can be nil (JM) }
if len > 0 then
if len>0 then
begin
temp:=JLString(src).getBytes;
if len > length(temp) then
len := length(temp);
for i := 0 to len-1 do
res[i] := chr(temp[i]);
len:=length(temp);
if len>length(res) then
len:=length(res);
JLSystem.ArrayCopy(JLObject(temp),0,JLObject(@res),0,len);
end;
if len<=high(res) then
JUArrays.fill(TJByteArray(@res),len,high(res),0);
end;