Handle partial dives near the end of the ringbuffer correctly.
This commit is contained in:
parent
6242ba9a13
commit
471f079c2e
@ -292,13 +292,12 @@ mares_nemo_extract_dives (const unsigned char data[], unsigned int size, dive_ca
|
|||||||
unsigned int nsamples = buffer[offset - 3] + (buffer[offset - 2] << 8);
|
unsigned int nsamples = buffer[offset - 3] + (buffer[offset - 2] << 8);
|
||||||
|
|
||||||
// Calculate the total number of bytes for this dive.
|
// Calculate the total number of bytes for this dive.
|
||||||
// If the buffer does not contain that much bytes, something
|
// If the buffer does not contain that much bytes, we reached the
|
||||||
// is wrong and an error is returned.
|
// end of the ringbuffer. The current dive is incomplete (partially
|
||||||
|
// overwritten with newer data), and processing should stop.
|
||||||
unsigned int nbytes = 2 + nsamples * sample_size + header_size;
|
unsigned int nbytes = 2 + nsamples * sample_size + header_size;
|
||||||
if (offset < nbytes) {
|
if (offset < nbytes)
|
||||||
WARNING ("Ringbuffer contains fewer bytes than required.");
|
break;
|
||||||
return DEVICE_STATUS_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Move to the start of the dive.
|
// Move to the start of the dive.
|
||||||
offset -= nbytes;
|
offset -= nbytes;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user