[Ada] PR18847 Ada.Numerics.xx_Random.Value does not handle junk strings

Laurent GUERBY laurent@guerby.net
Sat Apr 9 15:19:00 GMT 2005


Ok the bug is trivial once I peek into the core dump:

(gdb) f 0
#0  0x00000000004212e5 in cxa5012__test_block__discrete_pack__value.779
() at a-nudira.adb:237
237           while Coded_State (Stop) /= ',' loop
(gdb) l
232           Start : Positive := Coded_State'First;
233           Stop  : Positive := Coded_State'First;
234           Outs  : State;
235
236        begin
237           while Coded_State (Stop) /= ',' loop
238              Stop := Stop + 1;
239           end loop;
240
241           Outs.X1 := Int'Value (Coded_State (Start .. Stop - 1));

The tests explicitely pass a junk string to
Ada.Numerics.Discrete_Random.Value and the loop above just goes until
something bad happens if it doesn't find a ',' soon enough.

The Ada RM says:

<<
A.5.2 Random Number Generation
[...]
                          Bounded (Run-Time) Errors

40.1/1 {8652/0050} {It is a bounded error to invoke Value with a string that
is not the image of any generator state.
{Program_Error (raised by failure of run-time check)}
{Constraint_Error (raised by failure of run-time check)} If the error is
detected, Constraint_Error or Program_Error is raised. Otherwise, a call to
Reset with the resulting state will produce a generator such that calls to
Random with this generator will produce a sequence of values of the
appropriate subtype, but which might not be random in character. That is, the
sequence of values might not fulfill the implementation requirements of this
subclause.}
>>

I will submit a patch that raises Constraint_Error in corner cases of
this function for both a-nudira.adb and a-nuflra.adb (which has the same
bug). Robert I assume this what we want?

Obviously low priority, this can wait after 4.0.0.

Laurent

On Sat, 2005-04-09 at 10:51 -0400, Daniel Jacobowitz wrote:
> On Sat, Apr 09, 2005 at 12:18:09PM +0200, Laurent GUERBY wrote:
> > Unfortunately this is a real core dump while running the test on my
> > machine (glibc-2.3.3-118 SuSE 9.2) at -O2 or -O0, and this does not
> > reproduce under GDB, see below. I don't know about valgrind on x86_64,
> > is it available?
> 
> Nope.  Your best bet would be to turn up ulimit -c and look at a core
> dump.
> 



More information about the Gcc mailing list