From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Ada.Strings.Fixed.Count raises Storage_Error
Date: Thu, 12 May 2016 17:56:36 -0500
Date: 2016-05-12T17:56:36-05:00 [thread overview]
Message-ID: <nh31n5$8cb$1@loke.gir.dk> (raw)
In-Reply-To: 57346ac8$0$4570$426a74cc@news.free.fr
Well, *anything* in Ada is allowed to raise Storage_Error (even the null
statement!), so formally the behavior is correct.
OTOH, there doesn't seem to be any actual running out of memory here, so it
is most likely a bug (especially as the other responses suggest that the
main problem is that the checks are suppressed in the library code). And
it's unlikely that the implementer expected this code to raise
Storage_Error.
Randy.
"Xavier Petit" <xpetit@becoast.fr> wrote in message
news:57346ac8$0$4570$426a74cc@news.free.fr...
> Hello, I would like to know if it is normal or a known bug.
>
> function Count
> (Source : String;
> Pattern : String;
> Mapping : Maps.Character_Mapping := Maps.Identity) return Natural;
>
> When Source'Last = Positive'Last and Pattern'Length = 1, I get
> Storage_Error, it seems this is because the checks are suppressed in
> this GNAT runtime function ? So with checks it would result a
> Constraint_Error ?
>
> Internally, the exit condition is tested after the index incrementation,
> so in this specific case the "Ind" index tries to store Positive'Last + 1.
> I think.
>
> Here the code :
>
> with Ada.Strings.Fixed, Ada.Integer_Text_IO;
> use Ada.Strings.Fixed, Ada.Integer_Text_IO;
>
> procedure Test_Count is
> S : constant String (Positive'Last - 2 .. Positive'Last) := "Ada";
> begin
> Put (Count (Source => S, Pattern => "AA"));
> Put (Count (Source => S (S'First .. S'Last - 1), Pattern => "A"));
> Put (Count (Source => S, Pattern => "A"));
> end;
>
> Output on gnat-gcc 5.3.1 :
>
> 0 1
>
> raised STORAGE_ERROR : stack overflow or erroneous memory access
>
>
> Thanks by advance
>
> --
> Xavier Petit
prev parent reply other threads:[~2016-05-12 22:56 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-12 11:36 Ada.Strings.Fixed.Count raises Storage_Error Xavier Petit
2016-05-12 15:22 ` Tero Koskinen
2016-05-12 22:05 ` Georg Bauhaus
2016-06-26 21:18 ` Victor Porton
2016-06-26 23:23 ` rieachus
2016-06-27 0:21 ` Jeffrey R. Carter
2016-06-27 4:00 ` rieachus
2016-06-27 0:51 ` Xavier Petit
2016-06-27 4:48 ` rieachus
2016-06-28 18:25 ` Xavier Petit
2016-06-29 18:49 ` Niklas Holsti
2016-06-29 19:40 ` Jeffrey R. Carter
2016-06-29 19:57 ` Dmitry A. Kazakov
2016-07-01 11:48 ` rieachus
2016-07-01 13:08 ` Dmitry A. Kazakov
2016-06-27 8:29 ` Simon Wright
2016-06-27 8:41 ` Georg Bauhaus
2016-06-29 8:15 ` Niklas Holsti
2016-06-29 9:13 ` J-P. Rosen
2016-06-29 17:43 ` Niklas Holsti
2016-06-29 18:19 ` J-P. Rosen
2016-06-29 20:30 ` Robert A Duff
2016-06-30 5:38 ` Niklas Holsti
2016-07-01 10:40 ` rieachus
2016-07-01 10:55 ` J-P. Rosen
2016-07-01 12:17 ` rieachus
2016-07-01 12:55 ` G.B.
2016-06-27 12:52 ` Victor Porton
2016-05-12 22:56 ` Randy Brukardt [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox