summaryrefslogtreecommitdiffstats
path: root/uemis.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2015-04-21 23:31:03 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-04-21 23:31:03 -0700
commit31b8dffbb166ca04e4b9c2e1717ab613b26261b7 (patch)
treeaac18dc57ce5cb7416a03f70f06d7b439293dca9 /uemis.c
parentf33a11bc8a73f13b193633c88f555e14aa7479b1 (diff)
downloadsubsurface-31b8dffbb166ca04e4b9c2e1717ab613b26261b7.tar.gz
Uemis downloader: don't use bogus sensor data from Uemis
Sometimes we get a sensor number of 255 - which gets turned into a tank index and then causes all kinds of havoc. Simply refuse to use a tank number larger than the maximum Subsurface has been compiled for. Oh, and use consistent variables to handle these unsigned 8 bit integers. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'uemis.c')
-rw-r--r--uemis.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/uemis.c b/uemis.c
index 690b1c98c..b2eda8f73 100644
--- a/uemis.c
+++ b/uemis.c
@@ -285,7 +285,7 @@ void uemis_parse_divelog_binary(char *base64, void *datap)
struct dive *dive = datap;
struct divecomputer *dc = &dive->dc;
int template, gasoffset;
- int active = 0;
+ uint8_t active = 0;
char version[5];
datalen = uemis_convert_base64(base64, &data);
@@ -334,10 +334,13 @@ void uemis_parse_divelog_binary(char *base64, void *datap)
i = 0x123;
u_sample = (uemis_sample_t *)(data + i);
while ((i <= datalen) && (data[i] != 0 || data[i+1] != 0)) {
- /* it seems that a dive_time of 0 indicates the end of the valid readings */
if (u_sample->active_tank != active) {
- active = u_sample->active_tank;
- add_gas_switch_event(dive, dc, u_sample->dive_time, active);
+ if (u_sample->active_tank >= MAX_CYLINDERS) {
+ fprintf(stderr, "got invalid sensor #%d was #%d\n", u_sample->active_tank, active);
+ } else {
+ active = u_sample->active_tank;
+ add_gas_switch_event(dive, dc, u_sample->dive_time, active);
+ }
}
sample = prepare_sample(dc);
sample->time.seconds = u_sample->dive_time;