From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!nntp-feed.chiark.greenend.org.uk!ewrotcd!reality.xs3.de!news.jacob-sparre.dk!loke.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Ada.Strings.Fixed.Count raises Storage_Error Date: Thu, 12 May 2016 17:56:36 -0500 Organization: JSA Research & Innovation Message-ID: References: <57346ac8$0$4570$426a74cc@news.free.fr> NNTP-Posting-Host: rrsoftware.com X-Trace: loke.gir.dk 1463093798 8587 24.196.82.226 (12 May 2016 22:56:38 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Thu, 12 May 2016 22:56:38 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Response X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 Xref: news.eternal-september.org comp.lang.ada:30396 Date: 2016-05-12T17:56:36-05:00 List-Id: 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" 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