Don't crash if add_gas_switch_event() gets called with invalid index

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2015-04-20 23:22:48 -07:00
parent 136282f88a
commit 216fa8d543

View file

@ -750,6 +750,9 @@ static void try_to_match_autogroup(const char *name, char *buf)
void add_gas_switch_event(struct dive *dive, struct divecomputer *dc, int seconds, int idx)
{
/* sanity check so we don't crash */
if (idx < 0 || idx >= MAX_CYLINDERS)
return;
/* The gas switch event format is insane for historical reasons */
struct gasmix *mix = &dive->cylinder[idx].gasmix;
int o2 = get_o2(mix);