+2005-04-16 Laurent GUERBY <laurent@guerby.net>
+
+ PR ada/18847
+ * a-nudira.adb (Value): Check for valid string.
+ * a-nuflra.adb (Value): Likewise.
+
2005-04-11 Richard Sandiford <rsandifo@redhat.com>
* lang.opt: Refer to the GCC internals documentation instead of c.opt.
-----------
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));
-----------
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));