* Fixed reading beyond input string in fpc_Val_Real_ShortStr if empty string was passed.

git-svn-id: trunk@5849 -
This commit is contained in:
yury 2007-01-08 15:12:48 +00:00
parent a2f4c7fd2a
commit 697875f5af

View File

@ -907,46 +907,46 @@ begin
flags:=0; flags:=0;
sign:=1; sign:=1;
while (code<=length(s)) and (s[code] in [' ',#9]) do while (code<=length(s)) and (s[code] in [' ',#9]) do
inc(code); inc(code);
case s[code] of if code<=length(s) then
'+' : inc(code); case s[code] of
'-' : begin '+' : inc(code);
sign:=-1; '-' : begin
inc(code); sign:=-1;
end; inc(code);
end; end;
end;
while (Code<=Length(s)) and (s[code] in ['0'..'9']) do while (Code<=Length(s)) and (s[code] in ['0'..'9']) do
begin begin
{ Read integer part } { Read integer part }
flags:=flags or 1; flags:=flags or 1;
fpc_Val_Real_ShortStr:=fpc_Val_Real_ShortStr*10+(ord(s[code])-ord('0'));
fpc_Val_Real_ShortStr:=fpc_Val_Real_ShortStr*10+(ord(s[code])-ord('0'));
inc(code); inc(code);
end; end;
{ Decimal ? } { Decimal ? }
if (length(s)>=code) and (s[code]='.') then if (length(s)>=code) and (s[code]='.') then
begin begin
hd:=1.0; hd:=1.0;
inc(code); inc(code);
while (length(s)>=code) and (s[code] in ['0'..'9']) do while (length(s)>=code) and (s[code] in ['0'..'9']) do
begin begin
{ Read fractional part. } { Read fractional part. }
flags:=flags or 2; flags:=flags or 2;
fpc_Val_Real_ShortStr:=fpc_Val_Real_ShortStr*10+(ord(s[code])-ord('0')); fpc_Val_Real_ShortStr:=fpc_Val_Real_ShortStr*10+(ord(s[code])-ord('0'));
hd:=hd*10.0; hd:=hd*10.0;
inc(code); inc(code);
end; end;
fpc_Val_Real_ShortStr:=fpc_Val_Real_ShortStr/hd; fpc_Val_Real_ShortStr:=fpc_Val_Real_ShortStr/hd;
end; end;
{ Again, read integer and fractional part} { Again, read integer and fractional part}
if flags=0 then if flags=0 then
begin begin
fpc_Val_Real_ShortStr:=0.0; fpc_Val_Real_ShortStr:=0.0;
exit; exit;
end; end;
{ Exponent ? } { Exponent ? }
if (length(s)>=code) and (upcase(s[code])='E') then if (length(s)>=code) and (upcase(s[code])='E') then
begin begin
inc(code); inc(code);
if Length(s) >= code then if Length(s) >= code then
if s[code]='+' then if s[code]='+' then
@ -959,16 +959,16 @@ fpc_Val_Real_ShortStr:=fpc_Val_Real_ShortStr*10+(ord(s[code])-ord('0'));
end; end;
if (length(s)<code) or not(s[code] in ['0'..'9']) then if (length(s)<code) or not(s[code] in ['0'..'9']) then
begin begin
fpc_Val_Real_ShortStr:=0.0; fpc_Val_Real_ShortStr:=0.0;
exit; exit;
end; end;
while (length(s)>=code) and (s[code] in ['0'..'9']) do while (length(s)>=code) and (s[code] in ['0'..'9']) do
begin begin
exponent:=exponent*10; exponent:=exponent*10;
exponent:=exponent+ord(s[code])-ord('0'); exponent:=exponent+ord(s[code])-ord('0');
inc(code); inc(code);
end; end;
end; end;
{ evaluate sign } { evaluate sign }
{ (before exponent, because the exponent may turn it into a denormal) } { (before exponent, because the exponent may turn it into a denormal) }
fpc_Val_Real_ShortStr:=fpc_Val_Real_ShortStr*sign; fpc_Val_Real_ShortStr:=fpc_Val_Real_ShortStr*sign;
@ -999,10 +999,10 @@ fpc_Val_Real_ShortStr:=fpc_Val_Real_ShortStr*10+(ord(s[code])-ord('0'));
{ Not all characters are read ? } { Not all characters are read ? }
if length(s)>=code then if length(s)>=code then
begin begin
fpc_Val_Real_ShortStr:=0.0; fpc_Val_Real_ShortStr:=0.0;
exit; exit;
end; end;
{ success ! } { success ! }
code:=0; code:=0;
end; end;