This program runed in valgrind brings on error:

program val;
var
  n, e: Integer;
begin
  System.Val('', n, e);
end.


==18377== Conditional jump or move depends on uninitialised value(s)
==18377==    at 0x804EDC5:
SYSTEM_INITVAL$SHORTSTRING$BOOLEAN$BYTE$$LONGINT (sstrings.inc:768)
==18377==    by 0x804EEDA: fpc_val_sint_shortstr (sstrings.inc:819)
==18377==    by 0x805171A: fpc_val_sint_ansistr (astrings.inc:881)
==18377==    by 0x804827C: main (val.pas:5)

Problem is that InitVal does not take into account empty string.
And this little patch solves this for me.

Petr

-- 
Ing. Petr Kristan
.
EPOS PRO s.r.o., Bozeny Nemcove 2625, 530 02 Pardubice
tel: +420 466335223    Czech Republic (Eastern Europe) 
fax: +420 466510709
Index: inc/sstrings.inc
===================================================================
--- inc/sstrings.inc	(revision 10368)
+++ inc/sstrings.inc	(working copy)
@@ -759,12 +759,18 @@
 var
   Code : SizeInt;
 begin
+  code:=1;
+  negativ:=false;
+  base:=10;
+  if length(s)=0 then 
+    begin
+      InitVal:=code;
+      Exit;
+    end;
 {Skip Spaces and Tab}
-  code:=1;
   while (code<=length(s)) and (s[code] in [' ',#9]) do
    inc(code);
 {Sign}
-  negativ:=false;
   case s[code] of
    '-' : begin
            negativ:=true;
@@ -773,7 +779,6 @@
    '+' : inc(code);
   end;
 {Base}
-  base:=10;
   if code<=length(s) then
    begin
      case s[code] of
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply via email to