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!news.eternal-september.org!.POSTED!not-for-mail From: Natasha Kerensikova Newsgroups: comp.lang.ada Subject: Re: Can anyone help with GNAT.Perfect_Hash_Generators ? (Possible memory corruption) Date: Fri, 9 Sep 2016 06:04:30 -0000 (UTC) Organization: A noiseless patient Spider Message-ID: References: <397dd8cb-2afc-43cd-972d-3b1a5a90cd5d@googlegroups.com> <877fao24da.fsf@mid.deneb.enyo.de> <0b79fce9-b898-4a1c-91fb-ca41e87b4dd5@googlegroups.com> <08e0581a-30f1-4cc5-972c-2d6c539d9df6@googlegroups.com> Injection-Date: Fri, 9 Sep 2016 06:04:30 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="eab84d932a0f4c9d4606240766f0f5e7"; logging-data="31304"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX189+qQkk7zU3aAjo9V93UkN" User-Agent: slrn/1.0.2 (FreeBSD) Cancel-Lock: sha1:ss8c9oEW2cthYGkp82gvfElpEo4= Xref: news.eternal-september.org comp.lang.ada:31735 Date: 2016-09-09T06:04:30+00:00 List-Id: Hello, On 2016-09-08, Jeffrey R. Carter wrote: > On 09/08/2016 11:03 AM, Anh Vo wrote: >> On Thursday, September 8, 2016 at 10:04:06 AM UTC-7, Simon Wright wrote: >>> Anh Vo writes: >>> >>>> Then, what would be the proper fix? >>> >>> To what? If you mean the apparent bug in GNAT.Perfect_Hash_Generators >> >> Yes. > > Clearly it needs to have the assumption, that all Strings have a lower bound of > 1, eliminated. > I thought it would be easier to make the assumption internally true instead. Since the first thing it does with the input is to copy it internally using the function New_Word, I would propose a fix along the line of replacing it from function New_Word (S : String) return Word_Type is begin return new String'(S); end New_Word; to function New_Word (S : String) return Word_Type is Result : Word_Type := new String (1 .. S'Length); begin Result.all := S; return Result; end New_Word; That way there is no need to gather a deep understanding of the algorithm to hunt all the places that rely on 'First = 1. And I don't see any loss of performance or readability with this change, in case anyone is worried about it. However I haven't found the time yet to seriously test such a fix. Natasha