From ffc3e598faa5d986d78e9a275c48193a3a835cfe Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Mon, 27 Apr 2020 21:12:24 +0200 Subject: core: create fake cylinder at end of cylinder table (hack!) When we had fixed-sized cylinder arrays, the planner used the last empty cylinder for "surface air". This was not recognized by the UI as a separate cylinder, because "empty cylinder" was the sentinel for the end of the table. The conversion to dynamically sized cylinder tables broke this code: everytime the surface segment is changed, a new dummy cylinder is added, which is visible in the UI. As a very temporary stop-gap fix, emulate the old code by creating a cylinder and then setting the end-of-table to before that cylinder. This means that we have to loosen the out-of-bound checks. That's all very scary and should be removed as soon as possible. Signed-off-by: Berthold Stoeger --- core/equipment.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'core/equipment.c') diff --git a/core/equipment.c b/core/equipment.c index 8d169d8d2..a5acb776d 100644 --- a/core/equipment.c +++ b/core/equipment.c @@ -368,7 +368,10 @@ cylinder_t *add_empty_cylinder(struct cylinder_table *t) */ cylinder_t *get_cylinder(const struct dive *d, int idx) { - if (idx < 0 || idx >= d->cylinders.nr) { + /* FIXME: The planner uses a dummy cylinder one past the official number of cylinders + * in the table to mark no-cylinder surface interavals. This is horrendous. Fix ASAP. */ + // if (idx < 0 || idx >= d->cylinders.nr) { + if (idx < 0 || idx >= d->cylinders.nr + 1 || idx >= d->cylinders.allocated) { fprintf(stderr, "Warning: accessing invalid cylinder %d (%d existing)\n", idx, d->cylinders.nr); return NULL; } -- cgit v1.2.3-70-g09d2