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,FREEMAIL_FROM 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!aioe.org!.POSTED!not-for-mail From: Victor Porton Newsgroups: comp.lang.ada Subject: Re: Ada.Strings.Fixed.Count raises Storage_Error Date: Mon, 27 Jun 2016 00:18:47 +0300 Organization: Aioe.org NNTP Server Message-ID: References: <57346ac8$0$4570$426a74cc@news.free.fr> NNTP-Posting-Host: gIixYTDYPXEsxkLTZ/4cyA.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Complaints-To: abuse@aioe.org User-Agent: KNode/4.14.10 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:30948 Date: 2016-06-27T00:18:47+03:00 List-Id: GNAT 6.1.1 on Debian Linux "testing": $ ./test_count 0 1 raised STORAGE_ERROR : stack overflow or erroneous memory access Let's decide who of us will report the bug, so that the report won't happen to be duplicate? Georg Bauhaus wrote: > On 12.05.16 13:36, Xavier Petit wrote: > >> 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 > > Compiling such that the RTS is recompiled will result in > > raised CONSTRAINT_ERROR : a-strsea.adb:102 overflow check failed > > The message points at a line in the implementation of > Ada.Strings.Search.Count, for the third of the calls. It reads > > Ind := Ind + 1; > > where Ind looks seems to be go along with the Index of your S, > IINM. Effectively (PL1 = Pattern'Length - 1 being 0), then loop > there boils down to this: > > while Ind <= Source'Last loop > if Pattern = Source (Ind .. Ind) then > ... > else > Ind := Ind + 1; > end if; > end loop; > > And this would explains the overflow. > > Just the slip-up that Ada subtypes were designed to help prevent? > > -- Victor Porton - http://portonvictor.org