From 216fa8d5439880785c2eaa7fccd29d9befa0280a Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Mon, 20 Apr 2015 23:22:48 -0700 Subject: Don't crash if add_gas_switch_event() gets called with invalid index Signed-off-by: Dirk Hohndel --- parse-xml.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/parse-xml.c b/parse-xml.c index 0abcfcb0c..a02c4afac 100644 --- a/parse-xml.c +++ b/parse-xml.c @@ -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); -- cgit v1.2.3-70-g09d2