Return the dives in reverse order (newest dives first).

This commit is contained in:
Jef Driesen 2008-05-15 14:20:32 +00:00
parent f37740be75
commit e8ce10ffb3

View File

@ -321,24 +321,26 @@ uwatec_smart_extract_dives (const unsigned char data[], unsigned int size, dive_
{ {
const unsigned char header[4] = {0xa5, 0xa5, 0x5a, 0x5a}; const unsigned char header[4] = {0xa5, 0xa5, 0x5a, 0x5a};
unsigned int offset = 0; // Search the data stream for start markers.
while (offset + 8 <= size) { unsigned int previous = size;
// Search for the header marker. unsigned int current = (size >= 4 ? size - 4 : 0);
if (memcmp (data + offset, header, sizeof (header)) == 0) { while (current > 0) {
current--;
if (memcmp (data + current, header, sizeof (header)) == 0) {
// Get the length of the profile data. // Get the length of the profile data.
unsigned int len = data[offset + 4] + (data[offset + 5] << 8) + unsigned int len = data[current + 4] + (data[current + 5] << 8) +
(data[offset + 6] << 16) + (data[offset + 7] << 24); (data[current + 6] << 16) + (data[current + 7] << 24);
// Check for a buffer overflow. // Check for a buffer overflow.
if (offset + len > size) if (current + len > previous)
return UWATEC_ERROR; return UWATEC_ERROR;
if (callback) if (callback)
callback (data + offset, len, userdata); callback (data + current, len, userdata);
offset += len; // Prepare for the next dive.
} else { previous = current;
offset++; current = (current >= 4 ? current - 4 : 0);
} }
} }