From 8c947bd6f795f45712bdd3f4c2a63f5cfc8797f5 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Sat, 19 Mar 2011 21:47:01 +0100 Subject: [PATCH] Fix the parsing of HelO2 dives lacking the additional 12 byte block. --- src/suunto_d9_parser.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/suunto_d9_parser.c b/src/suunto_d9_parser.c index 86e9411..515c7ee 100644 --- a/src/suunto_d9_parser.c +++ b/src/suunto_d9_parser.c @@ -220,8 +220,13 @@ suunto_d9_parser_samples_foreach (parser_t *abstract, sample_callback_t callback // Offset to the profile data. unsigned int profile = config + 2 + nparams * 3; - if (parser->model == 0x15) - profile += 12; // HelO2 + if (profile + 5 > size) + return PARSER_STATUS_ERROR; + + // HelO2 dives can have an additional data block. + const unsigned char sequence[] = {0x01, 0x00, 0x00}; + if (parser->model == 0x15 && memcmp (data + profile, sequence, sizeof (sequence)) != 0) + profile += 12; if (profile + 5 > size) return PARSER_STATUS_ERROR;