mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
52d8d89f73
commit
794066b236
30 changed files with 149 additions and 148 deletions
|
@ -32,7 +32,7 @@ static QString getFormattedWeight(const struct dive *dive, int idx)
|
|||
|
||||
static QString getFormattedCylinder(const struct dive *dive, int idx)
|
||||
{
|
||||
const cylinder_t *cyl = &dive->cylinders.cylinders[idx];
|
||||
const cylinder_t *cyl = get_cylinder(dive, idx);
|
||||
const char *desc = cyl->type.description;
|
||||
if (!desc && idx > 0)
|
||||
return QString();
|
||||
|
@ -46,7 +46,7 @@ static QString getFormattedCylinder(const struct dive *dive, int idx)
|
|||
|
||||
static QString getPressures(const struct dive *dive, int i, enum returnPressureSelector ret)
|
||||
{
|
||||
const cylinder_t *cyl = &dive->cylinders.cylinders[i];
|
||||
const cylinder_t *cyl = get_cylinder(dive, i);
|
||||
QString fmt;
|
||||
if (ret == START_PRESSURE) {
|
||||
if (cyl->start.mbar)
|
||||
|
@ -104,10 +104,10 @@ static QString formatGas(const dive *d)
|
|||
for (int i = 0; i < d->cylinders.nr; i++) {
|
||||
if (!is_cylinder_used(d, i))
|
||||
continue;
|
||||
gas = d->cylinders.cylinders[i].type.description;
|
||||
gas = get_cylinder(d, i)->type.description;
|
||||
if (!gas.isEmpty())
|
||||
gas += QChar(' ');
|
||||
gas += gasname(d->cylinders.cylinders[i].gasmix);
|
||||
gas += gasname(get_cylinder(d, i)->gasmix);
|
||||
// if has a description and if such gas is not already present
|
||||
if (!gas.isEmpty() && gases.indexOf(gas) == -1) {
|
||||
if (!gases.isEmpty())
|
||||
|
@ -167,8 +167,8 @@ static QVector<CylinderObjectHelper> makeCylinderObjects(const dive *d)
|
|||
QVector<CylinderObjectHelper> res;
|
||||
for (int i = 0; i < d->cylinders.nr; i++) {
|
||||
//Don't add blank cylinders, only those that have been defined.
|
||||
if (d->cylinders.cylinders[i].type.description)
|
||||
res.append(CylinderObjectHelper(&d->cylinders.cylinders[i])); // no emplace for QVector. :(
|
||||
if (get_cylinder(d, i)->type.description)
|
||||
res.append(CylinderObjectHelper(get_cylinder(d, i))); // no emplace for QVector. :(
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
@ -178,7 +178,7 @@ QStringList formatGetCylinder(const dive *d)
|
|||
QStringList getCylinder;
|
||||
for (int i = 0; i < d->cylinders.nr; i++) {
|
||||
if (is_cylinder_used(d, i))
|
||||
getCylinder << d->cylinders.cylinders[i].type.description;
|
||||
getCylinder << get_cylinder(d, i)->type.description;
|
||||
}
|
||||
return getCylinder;
|
||||
}
|
||||
|
@ -208,7 +208,7 @@ QStringList getFirstGas(const dive *d)
|
|||
QStringList gas;
|
||||
for (int i = 0; i < d->cylinders.nr; i++) {
|
||||
if (is_cylinder_used(d, i))
|
||||
gas << get_gas_string(d->cylinders.cylinders[i].gasmix);
|
||||
gas << get_gas_string(get_cylinder(d, i)->gasmix);
|
||||
}
|
||||
return gas;
|
||||
}
|
||||
|
@ -239,7 +239,7 @@ QStringList getFullCylinderList()
|
|||
int i = 0;
|
||||
for_each_dive (i, d) {
|
||||
for (int j = 0; j < d->cylinders.nr; j++)
|
||||
addStringToSortedList(cylinders, d->cylinders.cylinders[j].type.description);
|
||||
addStringToSortedList(cylinders, get_cylinder(d, j)->type.description);
|
||||
}
|
||||
|
||||
for (int ti = 0; ti < MAX_TANK_INFO; ti++)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue