From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-65-14.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: strange cursor in nested containers Date: Wed, 19 Apr 2023 16:07:00 +0100 Organization: A noiseless patient Spider Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain Injection-Info: dont-email.me; posting-host="40e9c7e81895f811b59dc5c65377c5ce"; logging-data="107378"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+rWU677ltPiDnS9nSYQhlkPmNcTlsD9Pg=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.1 (darwin) Cancel-Lock: sha1:Y0Dr5fCRr7N9Qi2azng//+/uFf8= sha1:4vvgL6cLWmLfzn0kVJ+fbYWaMHo= Xref: news.eternal-september.org comp.lang.ada:65114 List-Id: Mario Blunk writes: > I've put together a demo to reproduce a strange behavior of a cursor. > > https://github.com/Blunk-electronic/ada_training/blob/master/src/containers/demo/nested/nest_1.adb > > Description: > Inside the procedure "get_line" the cursor "result" is assigned only > once (on match). Since there is no further match, in the course of the > procedure, I assume that "result" is never changed. So the expected > output should be: > > net: A > L1 S: 2.00000E+00 E: 3.00000E+00 > L2 S: 2.00000E+00 E: 3.00000E+00 > net: B > L2 S: 2.00000E+00 E: 3.00000E+00 > L3 S: 2.00000E+00 E: 3.00000E+00 > > but the actual output is: > > net: A > L1 S: 2.00000E+00 E: 3.00000E+00 > L2 S: 2.00000E+00 E: 3.00000E+00 > net: B > L2 S: 1.20000E+01 E: 1.30000E+01 > L3 S: 7.47956E-39 E: 0.00000E+00 -- changes randomly This is a puzzler. To simplify matters (for me, anyway) I changed your doubly linked list to a vector. Now, instead of junk, I get an access violation. 'result' isn't changed, but a Cursor contains a pointer to the container and an index; using gdb to look at the container via the unchanged pointer, it's been overwritten with garbage. However, looping with this (after the Nets.Iterate call, i.e. after Result has been damaged) for N of Nets loop for TL of N.Lines loop Put_Line (To_String (TL)); end loop; end loop; works just fine. My head hurts.