Fix a subtle bug in the previous commit.
The workaround in the previous commit has a bug. If after a reset, the first entry happens to be located near the end of the TOC, then after a few dives, the TOC will overflow and new entries will be written at the start of the TOC. But the current algorithm starts scanning the TOC from the start and abort the scan as soon as an empty entry is found. Thus if there are less than 256 dives present, those entries near the end will never be reached. We now ignore all uninitialized entries, when searching for the most recent dive. An explicit safety check is added in case dives are unexpectedly interleaved with empty entries.
This commit is contained in:
parent
5d6408ed2f
commit
23658b55c8
@ -374,12 +374,8 @@ hw_ostc3_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, voi
|
||||
unsigned int offset = i * RB_LOGBOOK_SIZE;
|
||||
|
||||
// Ignore uninitialized header entries.
|
||||
if (array_isequal (header + offset, RB_LOGBOOK_SIZE, 0xFF)) {
|
||||
if (count)
|
||||
break;
|
||||
else
|
||||
continue;
|
||||
}
|
||||
if (array_isequal (header + offset, RB_LOGBOOK_SIZE, 0xFF))
|
||||
continue;
|
||||
|
||||
// Get the internal dive number.
|
||||
unsigned int current = array_uint16_le (header + offset + 80);
|
||||
@ -399,6 +395,14 @@ hw_ostc3_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, voi
|
||||
unsigned int idx = (latest + RB_LOGBOOK_COUNT - i) % RB_LOGBOOK_COUNT;
|
||||
unsigned int offset = idx * RB_LOGBOOK_SIZE;
|
||||
|
||||
// Uninitialized header entries should no longer be present at this
|
||||
// stage, unless the dives are interleaved with empty entries. But
|
||||
// that's something we don't support at all.
|
||||
if (array_isequal (header + offset, RB_LOGBOOK_SIZE, 0xFF)) {
|
||||
WARNING (abstract->context, "Unexpected empty header found.");
|
||||
break;
|
||||
}
|
||||
|
||||
// Get the firmware version.
|
||||
unsigned int firmware = array_uint16_be (header + offset + 0x30);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user