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,WEIRD_QUOTING 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: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Can anyone help with GNAT.Perfect_Hash_Generators ? (Possible memory corruption) Date: Tue, 06 Sep 2016 22:04:43 +0100 Organization: A noiseless patient Spider Message-ID: References: <397dd8cb-2afc-43cd-972d-3b1a5a90cd5d@googlegroups.com> <877fao24da.fsf@mid.deneb.enyo.de> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="90a7515de723fda2443060f3e878f4b0"; logging-data="27816"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18PQ8ZojHN59YHeYrk6K+HIiYOFiEMpp2w=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (darwin) Cancel-Lock: sha1:U/0+6c0v0HzCJtANbOdyExQ8ZPg= sha1:iI7F1QUTpHp0ac0DJfgmwrsCq80= Xref: news.eternal-september.org comp.lang.ada:31715 Date: 2016-09-06T22:04:43+01:00 List-Id: Florian Weimer writes: > * Natasha Kerensikova: (BTW, phg4 failed badly with "too many tries" or some such) >> So at this my conclusion is that GNAT.Perfect_Hash_Generators somehow >> works fine with 1-based string, but has trouble dealing with strings >> with larger indices. > > Yes, that's reasonable to assume. It's a relatively common source of > bugs in Ada library code. > > One way to pin-point this further is to makea copy of the > g-pehage.ads, g-pehage.adb files, rename the package, and compile it > as part of your project, so that the usual Ada checks aren't > eliminated. Yes. With phg2, under gdb, macOS, GNAT GPL 2016, Catchpoint 1, CONSTRAINT_ERROR (perfect_hash_generators.adb:2268 index check failed) at 0x000000010000e03e in perfect_hash_generators.select_char_position.count_different_keys ( table=..., last=1, pos=1) at perfect_hash_generators.adb:2268 2268 C := WT.Table (Reduced (K))(Pos); (gdb) l 2263 2264 -- Count the occurrences of the different characters 2265 2266 N := (others => 0); 2267 for K in Table (S).First .. Table (S).Last loop 2268 C := WT.Table (Reduced (K))(Pos); 2269 N (C) := N (C) + 1; 2270 end loop; 2271 2272 -- Update the number of different keys. Each character used (gdb) bt #0 <__gnat_debug_raise_exception> (e=0x100059440, message=...) at s-excdeb.adb:43 #1 0x0000000100019e8c in ada.exceptions.complete_occurrence (x=0x100500af0) at a-except.adb:925 #2 0x0000000100019e9b in ada.exceptions.complete_and_propagate_occurrence ( x=0x100500af0) at a-except.adb:936 #3 0x000000010001a2a6 in ada.exceptions.raise_with_location_and_msg (e=0x100059440, f=(system.address) 0x10003ca64, l=2268, c=0, m=(system.address) 0x10003e640) at a-except.adb:1162 #4 0x0000000100019e61 in <__gnat_raise_constraint_error_msg> (file=, line=, column=, msg=) at a-except.adb:891 #5 0x000000010001a390 in <__gnat_rcheck_CE_Index_Check> (file=, line=) at a-except.adb:1237 #6 0x000000010000e03e in perfect_hash_generators.select_char_position.count_different_keys (table=..., last=1, pos=1) at perfect_hash_generators.adb:2268 #7 0x000000010000ca72 in perfect_hash_generators.select_char_position () at perfect_hash_generators.adb:2326 #8 0x000000010000354b in perfect_hash_generators.compute (position=...) at perfect_hash_generators.adb:685 #9 0x000000010000f466 in phg2 () at phg2.adb:52 (gdb) p k $1 = 67 (gdb) p pos $2 = 1 (gdb) p reduced(k) $3 = 322 (gdb) p table(s) $4 = (first => 0, last => 253) ... gdb doesn't know what WT.Table is ... it's in an instantiation of gnat.table .. You were right about the strings, this with Ada.Text_IO; procedure Str is type A is access String; S : String := "xxxhelloyyy"; P : A; begin P := new String'(S (4 .. 8)); Ada.Text_IO.Put_Line ("""" & P.all & """ has indices" & P.all'First'Img & " .." & P.all'Last'Img); end Str; gives $ ./str "hello" has indices 4 .. 8