Be more careful about dive computer selection

The selection logic was a bit random: some places would return NULL if
the dive computer index was out of range, others would return the
primary dive computer, and actually moving between dive computers would
just blindly increment and decrement the number.

This always selects the primary computer if the index is out of bounds,
and makes sure we stay in bound when switching beteen dive computers
(but switching between dives can then turn an in-bound number into an
out-of-bounds one)

Fixes #464

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Linus Torvalds 2014-03-17 08:19:09 -07:00 committed by Dirk Hohndel
parent 60ceb8ebc1
commit 37794e2e23
8 changed files with 41 additions and 38 deletions

View file

@ -183,7 +183,7 @@ void DivePlotDataModel::calculateDecompression()
struct dive *d = getDiveById(id());
if (!d)
return;
struct divecomputer *dc = select_dc(&d->dc);
struct divecomputer *dc = select_dc(d);
init_decompression(d);
calculate_deco_information(d, dc, &pInfo, false);
dataChanged(index(0, CEILING), index(pInfo.nr - 1, TISSUE_16));