From ef47084e0553a38429744fefa086ab2247d7e0d1 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Tue, 17 Jan 2017 22:57:25 +0100 Subject: [PATCH] Skip the extra samples one by one Skipping the extra samples by increasing the length is not always reliable. If there are empty samples present, they will get skipped instead of the real samples. And if the number of samples isn't an exact multiple of the samplerate, we're accessing data beyond the end of the dive profile. --- src/oceanic_atom2_parser.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/oceanic_atom2_parser.c b/src/oceanic_atom2_parser.c index fda96a5..12b832f 100644 --- a/src/oceanic_atom2_parser.c +++ b/src/oceanic_atom2_parser.c @@ -671,6 +671,7 @@ oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_ // Initial gas mix. unsigned int gasmix_previous = 0xFFFFFFFF; + unsigned int count = 0; unsigned int complete = 1; unsigned int offset = parser->headersize; while (offset + samplesize <= size - parser->footersize) { @@ -700,7 +701,7 @@ oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_ // The sample size is usually fixed, but some sample types have a // larger size. Check whether we have that many bytes available. - unsigned int length = samplesize * samplerate; + unsigned int length = samplesize; if (sampletype == 0xBB) { length = PAGESIZE; if (offset + length > size - PAGESIZE) @@ -751,6 +752,13 @@ oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_ complete = 1; } } else { + // Skip the extra samples. + if ((count % samplerate) != 0) { + offset += samplesize; + count++; + continue; + } + // Temperature (°F) if (have_temperature) { if (parser->model == GEO || parser->model == ATOM1 || @@ -912,6 +920,7 @@ oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_ if (callback) callback (DC_SAMPLE_RBT, sample, userdata); } + count++; complete = 1; }