Core: dynamically allocate the result of get_gas_used()

get_gas_used() returns the volume of used gases. Currently,
an array with MAX_CYLINDERS is passed in. If we want to make the
number of cylinders dynamic, the function must use an arbitrarilly
sized array.

Therefore, return a dynamically allocated array and free it
in the caller.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2019-06-27 07:42:09 +02:00 committed by Dirk Hohndel
parent f179ec033f
commit 11467fa326
5 changed files with 16 additions and 10 deletions

View file

@ -388,13 +388,14 @@ QVector<QPair<QString, int>> selectedDivesGasUsed()
for_each_dive (i, d) {
if (!d->selected)
continue;
volume_t diveGases[MAX_CYLINDERS] = {};
get_gas_used(d, diveGases);
for (j = 0; j < MAX_CYLINDERS; j++)
volume_t *diveGases = get_gas_used(d);
for (j = 0; j < MAX_CYLINDERS; j++) {
if (diveGases[j].mliter) {
QString gasName = gasname(d->cylinder[j].gasmix);
gasUsed[gasName] += diveGases[j].mliter;
}
}
free(diveGases);
}
QVector<QPair<QString, int>> gasUsedOrdered;
gasUsedOrdered.reserve(gasUsed.size());