diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-08-04 22:13:49 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-11-09 19:19:04 +0100 |
commit | 794066b2367082851858d4e0da8b6e388d2acabb (patch) | |
tree | 81aad4f5e50c096a25d4bf59491a05ec250b6bc9 /smtk-import | |
parent | 52d8d89f73542eb8ab3577bc55b466e7ca73bfc7 (diff) | |
download | subsurface-794066b2367082851858d4e0da8b6e388d2acabb.tar.gz |
Cylinders: access cylinders with get_cylinder()
Instead of accessing the cylinder table directly, use the get_cylinder()
function. This gives less unwieldy expressions. But more importantly,
the function does bound checking. This is crucial for now as the code
hasn't be properly audited since the change to arbitrarily sized
cylinder tables. Accesses of invalid cylinder indexes may lead to
silent data-corruption that is sometimes not even noticed by
valgrind. Returning NULL instead of an invalid pointer will make
debugging much easier.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'smtk-import')
-rw-r--r-- | smtk-import/smartrak.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/smtk-import/smartrak.c b/smtk-import/smartrak.c index 64a613fc7..5054297ab 100644 --- a/smtk-import/smartrak.c +++ b/smtk-import/smartrak.c @@ -507,7 +507,7 @@ static void merge_cylinder_info(cylinder_t *src, cylinder_t *dst) static int smtk_clean_cylinders(struct dive *d) { int i = tanks - 1; - cylinder_t *cyl, *base = &d->cylinders.cylinders[0]; + cylinder_t *cyl, *base = get_cylinder(d, 0); cyl = base + tanks - 1; while (cyl != base) { @@ -1038,24 +1038,24 @@ void smartrak_import(const char *file, struct dive_table *divetable) int tankidxcol = coln(TANKIDX); for (i = 0; i < tanks; i++) { - if (smtkdive->cylinders.cylinders[i].start.mbar == 0) - smtkdive->cylinders.cylinders[i].start.mbar = lrint(strtod(col[(i * 2) + pstartcol]->bind_ptr, NULL) * 1000); + if (get_cylinder(smtkdive, i)->start.mbar == 0) + get_cylinder(smtkdive, i)->start.mbar = lrint(strtod(col[(i * 2) + pstartcol]->bind_ptr, NULL) * 1000); /* * If there is a start pressure ensure that end pressure is not zero as * will be registered in DCs which only keep track of differential pressures, * and collect the data registered by the user in mdb */ - if (smtkdive->cylinders.cylinders[i].end.mbar == 0 && smtkdive->cylinders.cylinders[i].start.mbar != 0) - smtkdive->cylinders.cylinders[i].end.mbar = lrint(strtod(col[(i * 2) + 1 + pstartcol]->bind_ptr, NULL) * 1000 ? : 1000); - if (smtkdive->cylinders.cylinders[i].gasmix.o2.permille == 0) - smtkdive->cylinders.cylinders[i].gasmix.o2.permille = lrint(strtod(col[i + o2fraccol]->bind_ptr, NULL) * 10); + if (get_cylinder(smtkdive, i)->end.mbar == 0 && get_cylinder(smtkdive, i)->start.mbar != 0) + get_cylinder(smtkdive, i)->end.mbar = lrint(strtod(col[(i * 2) + 1 + pstartcol]->bind_ptr, NULL) * 1000 ? : 1000); + if (get_cylinder(smtkdive, i)->gasmix.o2.permille == 0) + get_cylinder(smtkdive, i)->gasmix.o2.permille = lrint(strtod(col[i + o2fraccol]->bind_ptr, NULL) * 10); if (smtk_version == 10213) { - if (smtkdive->cylinders.cylinders[i].gasmix.he.permille == 0) - smtkdive->cylinders.cylinders[i].gasmix.he.permille = lrint(strtod(col[i + hefraccol]->bind_ptr, NULL) * 10); + if (get_cylinder(smtkdive, i)->gasmix.he.permille == 0) + get_cylinder(smtkdive, i)->gasmix.he.permille = lrint(strtod(col[i + hefraccol]->bind_ptr, NULL) * 10); } else { - smtkdive->cylinders.cylinders[i].gasmix.he.permille = 0; + get_cylinder(smtkdive, i)->gasmix.he.permille = 0; } - smtk_build_tank_info(mdb_clon, &smtkdive->cylinders.cylinders[i], col[i + tankidxcol]->bind_ptr); + smtk_build_tank_info(mdb_clon, get_cylinder(smtkdive, i), col[i + tankidxcol]->bind_ptr); } /* Check for duplicated cylinders and clean them */ smtk_clean_cylinders(smtkdive); |