Cleanup: prevent out of bounds read

Don't access cylinder[MAX_CYLINDERS]

Coverity CID 208324

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2017-12-26 14:25:57 -08:00
parent 1a46f5eb9b
commit f4237bf843

View file

@ -245,7 +245,7 @@ struct gasmix *get_gasmix_from_event(struct dive *dive, struct event *ev)
static struct gasmix dummy;
if (ev && event_is_gaschange(ev)) {
int index = ev->gas.index;
if (index >= 0 && index <= MAX_CYLINDERS)
if (index >= 0 && index < MAX_CYLINDERS)
return &dive->cylinder[index].gasmix;
return &ev->gas.mix;
}
@ -756,7 +756,7 @@ struct sample *prepare_sample(struct divecomputer *dc)
// Init some values with -1
sample->bearing.degrees = -1;
sample->ndl.seconds = -1;
return sample;
}
return NULL;