summaryrefslogtreecommitdiffstats
path: root/dive.c
diff options
context:
space:
mode:
authorGravatar Robert C. Helling <helling@atdotde.de>2014-12-31 00:00:24 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-12-30 15:54:52 -0800
commitac067fb42414627835efe682615a92f754eb1a08 (patch)
treee93e1aee8e040b4089df650c7622a146805145c4 /dive.c
parentc5d3d923a0cd84b6e92e5a451a2fcead996b6e99 (diff)
downloadsubsurface-ac067fb42414627835efe682615a92f754eb1a08.tar.gz
Prevent holes in cylinder list when copying used ones
This ensures that the list of configured cylinders is consecutive. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'dive.c')
-rw-r--r--dive.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/dive.c b/dive.c
index ad9d6dadb..adc8d0d18 100644
--- a/dive.c
+++ b/dive.c
@@ -567,19 +567,22 @@ int nr_weightsystems(struct dive *dive)
/* copy the equipment data part of the cylinders */
void copy_cylinders(struct dive *s, struct dive *d, bool used_only)
{
- int i;
+ int i,j;
if (!s || !d)
return;
for (i = 0; i < MAX_CYLINDERS; i++) {
free((void *)d->cylinder[i].type.description);
memset(&d->cylinder[i], 0, sizeof(cylinder_t));
+ }
+ for (i = j = 0; i < MAX_CYLINDERS; i++) {
if (!used_only || is_cylinder_used(s, i)) {
- d->cylinder[i].type = s->cylinder[i].type;
- d->cylinder[i].type.description = copy_string(s->cylinder[i].type.description);
- d->cylinder[i].gasmix = s->cylinder[i].gasmix;
- d->cylinder[i].depth = s->cylinder[i].depth;
- d->cylinder[i].cylinder_use = s->cylinder[i].cylinder_use;
- d->cylinder[i].manually_added = true;
+ d->cylinder[j].type = s->cylinder[i].type;
+ d->cylinder[j].type.description = copy_string(s->cylinder[i].type.description);
+ d->cylinder[j].gasmix = s->cylinder[i].gasmix;
+ d->cylinder[j].depth = s->cylinder[i].depth;
+ d->cylinder[j].cylinder_use = s->cylinder[i].cylinder_use;
+ d->cylinder[j].manually_added = true;
+ j++;
}
}
}