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 /profile-widget | |
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 'profile-widget')
-rw-r--r-- | profile-widget/diveprofileitem.cpp | 2 | ||||
-rw-r--r-- | profile-widget/profilewidget2.cpp | 6 | ||||
-rw-r--r-- | profile-widget/tankitem.cpp | 2 |
3 files changed, 5 insertions, 5 deletions
diff --git a/profile-widget/diveprofileitem.cpp b/profile-widget/diveprofileitem.cpp index 3d0ba2e7a..2d50ad222 100644 --- a/profile-widget/diveprofileitem.cpp +++ b/profile-widget/diveprofileitem.cpp @@ -748,7 +748,7 @@ void DiveGasPressureItem::modelDataChanged(const QModelIndex &topLeft, const QMo label_y_offset = -7 * axisLog; } plotPressureValue(mbar, entry->sec, alignVar, value_y_offset); - plotGasValue(mbar, entry->sec, displayed_dive.cylinders.cylinders[cyl].gasmix, alignVar, label_y_offset); + plotGasValue(mbar, entry->sec, get_cylinder(&displayed_dive, cyl)->gasmix, alignVar, label_y_offset); seen_cyl[cyl] = true; /* Alternate alignment as we see cylinder use.. */ diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp index 01cd733be..ccbae7cc4 100644 --- a/profile-widget/profilewidget2.cpp +++ b/profile-widget/profilewidget2.cpp @@ -1536,7 +1536,7 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event) int newGasIdx = gasChangeIdx + 1; const struct plot_data &newGasEntry = plotInfo.entry[newGasIdx]; qDebug() << "after gas change at " << newGasEntry->sec << ": sensor pressure" << newGasEntry->pressure[0] << "interpolated" << newGasEntry->pressure[1]; - if (get_plot_sensor_pressure(&plotInfo, gasChangeIdx) == 0 || displayed_dive.cylinders.cylinders[gasChangeEntry->sensor[0]].sample_start.mbar == 0) { + if (get_plot_sensor_pressure(&plotInfo, gasChangeIdx) == 0 || get_cylinder(&displayed_dive, gasChangeEntry->sensor[0])->sample_start.mbar == 0) { // if we have no sensorpressure or if we have no pressure from samples we can assume that // we only have interpolated pressure (the pressure in the entry may be stored in the sensor // pressure field if this is the first or last entry for this tank... see details in gaspressures.c @@ -1545,7 +1545,7 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event) QAction *adjustOldPressure = m.addAction(tr("Adjust pressure of cyl. %1 (currently interpolated as %2)") .arg(gasChangeEntry->sensor[0] + 1).arg(get_pressure_string(pressure))); } - if (get_plot_sensor_pressure(&plotInfo, newGasIdx) == 0 || displayed_dive.cylinders.cylinders[newGasEntry->sensor[0]].sample_start.mbar == 0) { + if (get_plot_sensor_pressure(&plotInfo, newGasIdx) == 0 || get_cylinder(&displayed_dive, newGasEntry->sensor[0])->sample_start.mbar == 0) { // we only have interpolated press -- see commend above pressure_t pressure; pressure.mbar = get_plot_interpolated_pressure(&plotInfo, newGasIdx) ? : get_plot_sensor_pressure(&plotInfo, newGasIdx); @@ -1882,7 +1882,7 @@ void ProfileWidget2::repositionDiveHandlers() QLineF line(p1, p2); QPointF pos = line.pointAt(0.5); gases[i]->setPos(pos); - gases[i]->setText(get_gas_string(displayed_dive.cylinders.cylinders[datapoint.cylinderid].gasmix)); + gases[i]->setText(get_gas_string(get_cylinder(&displayed_dive, datapoint.cylinderid)->gasmix)); gases[i]->setVisible(datapoint.entered && (i == 0 || gases[i]->text() != gases[i-1]->text())); } diff --git a/profile-widget/tankitem.cpp b/profile-widget/tankitem.cpp index e3233184c..4967633ed 100644 --- a/profile-widget/tankitem.cpp +++ b/profile-widget/tankitem.cpp @@ -97,7 +97,7 @@ void TankItem::modelDataChanged(const QModelIndex&, const QModelIndex&) // start with the first gasmix and at the start of the dive int cyl = explicit_first_cylinder(&displayed_dive, dc); - struct gasmix gasmix = displayed_dive.cylinders.cylinders[cyl].gasmix; + struct gasmix gasmix = get_cylinder(&displayed_dive, cyl)->gasmix; int startTime = 0; // work through all the gas changes and add the rectangle for each gas while it was used |