Browse Source

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

git-svn-id: trunk@5849 -
yury 18 years ago
parent
commit
697875f5af
1 changed files with 30 additions and 30 deletions
  1. 30 30
      rtl/inc/sstrings.inc

+ 30 - 30
rtl/inc/sstrings.inc

@@ -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);
-  case s[code] of
-   '+' : inc(code);
-   '-' : begin
-           sign:=-1;
-           inc(code);
-         end;
-  end;
+    inc(code);
+  if code<=length(s) then
+    case s[code] of
+     '+' : inc(code);
+     '-' : begin
+             sign:=-1;
+             inc(code);
+           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;
-           fpc_Val_Real_ShortStr:=fpc_Val_Real_ShortStr*10+(ord(s[code])-ord('0'));
-           hd:=hd*10.0;
-           inc(code);
+          flags:=flags or 2;
+          fpc_Val_Real_ShortStr:=fpc_Val_Real_ShortStr*10+(ord(s[code])-ord('0'));
+          hd:=hd*10.0;
+          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;
-           exit;
+          fpc_Val_Real_ShortStr:=0.0;
+          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+ord(s[code])-ord('0');
-           inc(code);
+          exponent:=exponent*10;
+          exponent:=exponent+ord(s[code])-ord('0');
+          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
-     fpc_Val_Real_ShortStr:=0.0;
-     exit;
-   end;
+    begin
+      fpc_Val_Real_ShortStr:=0.0;
+      exit;
+    end;
 { success ! }
 { success ! }
   code:=0;
   code:=0;
 end;
 end;