Berthold Stoeger 9243921cbb test: fix subtle bug in testplan.cpp
testplan.cpp had a subtle bug since converting from a fixed-size
cylinder table to a dynamic cylinder table.

As noted in equipment.h, pointers to cylinders are *not* stable
when the cylinder table grows. Therefore, a construct such as
        cylinder_t *cyl0 = get_or_create_cylinder(&dive, 0);
        cylinder_t *cyl1 = get_or_create_cylinder(&dive, 1);
        cylinder_t *cyl2 = get_or_create_cylinder(&dive, 2);
can give dangling cyl0 and cyl1 pointers. This was not an issue
with the old table code, since it had a rather liberal allocation
pattern. However, when switching to std::vector<>, the problem
becomes active.

To "fix" this, simply access the highest index first. Of course,
this should never be done in real code! Therefore, add a
comment at each instance.

Quickly checked all other get_or_create_cylinder() calls and
they seemed to be safe.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-05-31 22:50:49 +02:00
..
2018-07-26 16:32:51 +03:00
2018-07-26 16:32:51 +03:00
2018-07-26 16:32:51 +03:00
2018-07-26 16:32:51 +03:00
2021-04-19 12:51:01 -07:00
2019-12-29 12:32:02 -08:00
2019-12-29 12:31:43 -08:00
2019-12-25 02:57:42 +09:00
2018-07-26 16:32:51 +03:00
2018-07-26 16:32:51 +03:00