This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH][4.0][Ada] Fix Ada.Numerics.xxx_Random.Value checking (PRada/18847
- From: Laurent GUERBY <laurent at guerby dot net>
- To: gcc-patches at gcc dot gnu dot org, dewar at adacore dot com, Arnaud Charlet <charlet at adacore dot com>
- Cc: Richard Kenner <kenner at vlsi1 dot ultra dot nyu dot edu>, Mark Mitchell <mark at codesourcery dot com>
- Date: Sat, 09 Apr 2005 23:06:11 +0200
- Subject: [PATCH][4.0][Ada] Fix Ada.Numerics.xxx_Random.Value checking (PRada/18847
Tested on 4.0 x86_64-linux where it fixes the cxa5012 failure.
Ok for 4.0 after 4.0.0 is out?
Ok for 4.1 (after bootstrap completes)?
Laurent
2005-04-09 Laurent GUERBY <laurent@guerby.net>
PR ada/18847
* a-nudira.adb (Value): Check for valid string.
* a-nuflra.adb (Value): Likewise.
Index: a-nudira.adb
===================================================================
RCS file: /cvs/gcc/gcc/gcc/ada/a-nudira.adb,v
retrieving revision 1.5
diff -u -r1.5 a-nudira.adb
--- a-nudira.adb 21 Oct 2003 13:41:53 -0000 1.5
+++ a-nudira.adb 9 Apr 2005 20:56:18 -0000
@@ -229,25 +229,34 @@
-----------
function Value (Coded_State : String) return State is
+ Last : constant Natural := Coded_State'Last;
Start : Positive := Coded_State'First;
Stop : Positive := Coded_State'First;
Outs : State;
begin
- while Coded_State (Stop) /= ',' loop
+ while Stop <= Last and then Coded_State (Stop) /= ',' loop
Stop := Stop + 1;
end loop;
+ if Stop > Last then
+ raise Constraint_Error;
+ end if;
+
Outs.X1 := Int'Value (Coded_State (Start .. Stop - 1));
Start := Stop + 1;
loop
Stop := Stop + 1;
- exit when Coded_State (Stop) = ',';
+ exit when Stop > Last or else Coded_State (Stop) = ',';
end loop;
+ if Stop > Last then
+ raise Constraint_Error;
+ end if;
+
Outs.X2 := Int'Value (Coded_State (Start .. Stop - 1));
- Outs.Q := Int'Value (Coded_State (Stop + 1 .. Coded_State'Last));
+ Outs.Q := Int'Value (Coded_State (Stop + 1 .. Last));
Outs.P := Outs.Q * 2 + 1;
Outs.FP := Flt (Outs.P);
Outs.Scl := (RstL - RstF + 1.0) / (Flt (Outs.P) * Flt (Outs.Q));
Index: a-nuflra.adb
===================================================================
RCS file: /cvs/gcc/gcc/gcc/ada/a-nuflra.adb,v
retrieving revision 1.5
diff -u -r1.5 a-nuflra.adb
--- a-nuflra.adb 21 Oct 2003 13:41:53 -0000 1.5
+++ a-nuflra.adb 9 Apr 2005 20:56:18 -0000
@@ -256,33 +256,46 @@
-----------
function Value (Coded_State : String) return State is
+ Last : constant Natural := Coded_State'Last;
Start : Positive := Coded_State'First;
Stop : Positive := Coded_State'First;
Outs : State;
begin
- while Coded_State (Stop) /= ',' loop
+ while Stop <= Last and then Coded_State (Stop) /= ',' loop
Stop := Stop + 1;
end loop;
+ if Stop > Last then
+ raise Constraint_Error;
+ end if;
+
Outs.X1 := Int'Value (Coded_State (Start .. Stop - 1));
Start := Stop + 1;
loop
Stop := Stop + 1;
- exit when Coded_State (Stop) = ',';
+ exit when Stop > Last or else Coded_State (Stop) = ',';
end loop;
+ if Stop > Last then
+ raise Constraint_Error;
+ end if;
+
Outs.X2 := Int'Value (Coded_State (Start .. Stop - 1));
Start := Stop + 1;
loop
Stop := Stop + 1;
- exit when Coded_State (Stop) = ',';
+ exit when Stop > Last or else Coded_State (Stop) = ',';
end loop;
+ if Stop > Last then
+ raise Constraint_Error;
+ end if;
+
Outs.P := Int'Value (Coded_State (Start .. Stop - 1));
- Outs.Q := Int'Value (Coded_State (Stop + 1 .. Coded_State'Last));
+ Outs.Q := Int'Value (Coded_State (Stop + 1 .. Last));
Outs.X := Euclid (Outs.P, Outs.Q);
Outs.Scl := 1.0 / (Flt (Outs.P) * Flt (Outs.Q));