comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: strange cursor in nested containers
Date: Wed, 19 Apr 2023 16:07:00 +0100	[thread overview]
Message-ID: <lyttxbc3mz.fsf@pushface.org> (raw)
In-Reply-To: a346f13d-9876-488a-9472-4563de130311n@googlegroups.com

Mario Blunk <mario.blunk.gplus@gmail.com> 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.

  reply	other threads:[~2023-04-19 15:07 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-19  7:09 strange cursor in nested containers Mario Blunk
2023-04-19 15:07 ` Simon Wright [this message]
2023-04-20  5:15 ` Egil H H
2023-04-20  5:33   ` Egil H H
2023-04-20 14:59   ` Simon Wright
2023-04-20 15:28     ` Mario Blunk
2023-04-22  9:33       ` Randy Brukardt
2023-04-22 17:04         ` Mario Blunk
2023-04-22 18:33           ` Jeffrey R.Carter
2023-04-25  7:30             ` Mario Blunk
2023-05-09  3:56               ` Randy Brukardt
2023-05-09  8:36                 ` Jeffrey R.Carter
2023-05-09  8:49                   ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox