Handle invalid logbook pointers as a fatal error.
Until now, an invalid logbook pointer was silently ignored and handled as an empty ringbuffer. But this hides real errors, which is worse than failing if no dives are present. Trying to download dives from an empty device should be a rather uncommon scenario anyway.
This commit is contained in:
parent
55eaadac0c
commit
cfc1a68b0d
@ -246,39 +246,33 @@ oceanic_common_device_foreach (dc_device_t *abstract, dc_dive_callback_t callbac
|
|||||||
// Get the logbook pointers.
|
// Get the logbook pointers.
|
||||||
unsigned int rb_logbook_first = array_uint16_le (pointers + 4);
|
unsigned int rb_logbook_first = array_uint16_le (pointers + 4);
|
||||||
unsigned int rb_logbook_last = array_uint16_le (pointers + 6);
|
unsigned int rb_logbook_last = array_uint16_le (pointers + 6);
|
||||||
|
|
||||||
// Convert the first/last pointers to begin/end/count pointers.
|
|
||||||
unsigned int rb_logbook_entry_begin, rb_logbook_entry_end,
|
|
||||||
rb_logbook_entry_size;
|
|
||||||
if (rb_logbook_first < layout->rb_logbook_begin ||
|
if (rb_logbook_first < layout->rb_logbook_begin ||
|
||||||
rb_logbook_first >= layout->rb_logbook_end ||
|
rb_logbook_first >= layout->rb_logbook_end ||
|
||||||
rb_logbook_last < layout->rb_logbook_begin ||
|
rb_logbook_last < layout->rb_logbook_begin ||
|
||||||
rb_logbook_last >= layout->rb_logbook_end)
|
rb_logbook_last >= layout->rb_logbook_end)
|
||||||
{
|
{
|
||||||
// One of the pointers is outside the valid ringbuffer area.
|
ERROR (abstract->context, "Invalid logbook pointer detected.");
|
||||||
// Because some devices use invalid pointers to indicate an
|
return DC_STATUS_DATAFORMAT;
|
||||||
// empty ringbuffer, we silently ignore the error and always
|
}
|
||||||
// consider the ringbuffer empty.
|
|
||||||
rb_logbook_entry_begin = layout->rb_logbook_begin;
|
// Convert the first/last pointers to begin/end/count pointers.
|
||||||
rb_logbook_entry_end = layout->rb_logbook_begin;
|
unsigned int rb_logbook_entry_begin, rb_logbook_entry_end,
|
||||||
rb_logbook_entry_size = 0;
|
rb_logbook_entry_size;
|
||||||
|
if (layout->pt_mode_global == 0) {
|
||||||
|
rb_logbook_entry_begin = rb_logbook_first;
|
||||||
|
rb_logbook_entry_end = RB_LOGBOOK_INCR (rb_logbook_last, layout->rb_logbook_entry_size, layout);
|
||||||
|
rb_logbook_entry_size = RB_LOGBOOK_DISTANCE (rb_logbook_first, rb_logbook_last, layout) + layout->rb_logbook_entry_size;
|
||||||
} else {
|
} else {
|
||||||
if (layout->pt_mode_global == 0) {
|
rb_logbook_entry_begin = rb_logbook_first;
|
||||||
rb_logbook_entry_begin = rb_logbook_first;
|
rb_logbook_entry_end = rb_logbook_last;
|
||||||
rb_logbook_entry_end = RB_LOGBOOK_INCR (rb_logbook_last, layout->rb_logbook_entry_size, layout);
|
rb_logbook_entry_size = RB_LOGBOOK_DISTANCE (rb_logbook_first, rb_logbook_last, layout);
|
||||||
rb_logbook_entry_size = RB_LOGBOOK_DISTANCE (rb_logbook_first, rb_logbook_last, layout) + layout->rb_logbook_entry_size;
|
// In a typical ringbuffer implementation with only two begin/end
|
||||||
} else {
|
// pointers, there is no distinction possible between an empty and
|
||||||
rb_logbook_entry_begin = rb_logbook_first;
|
// a full ringbuffer. We always consider the ringbuffer full in
|
||||||
rb_logbook_entry_end = rb_logbook_last;
|
// that case, because an empty ringbuffer can be detected by
|
||||||
rb_logbook_entry_size = RB_LOGBOOK_DISTANCE (rb_logbook_first, rb_logbook_last, layout);
|
// inspecting the logbook entries once they are downloaded.
|
||||||
// In a typical ringbuffer implementation with only two begin/end
|
if (rb_logbook_first == rb_logbook_last)
|
||||||
// pointers, there is no distinction possible between an empty and
|
rb_logbook_entry_size = layout->rb_logbook_end - layout->rb_logbook_begin;
|
||||||
// a full ringbuffer. We always consider the ringbuffer full in
|
|
||||||
// that case, because an empty ringbuffer can be detected by
|
|
||||||
// inspecting the logbook entries once they are downloaded.
|
|
||||||
if (rb_logbook_first == rb_logbook_last)
|
|
||||||
rb_logbook_entry_size = layout->rb_logbook_end - layout->rb_logbook_begin;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check whether the ringbuffer is full.
|
// Check whether the ringbuffer is full.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user