diff --git a/src/array.c b/src/array.c index 8484ecd..5c1763e 100644 --- a/src/array.c +++ b/src/array.c @@ -50,6 +50,18 @@ array_reverse_bits (unsigned char data[], unsigned int size) } +int +array_isequal (const unsigned char data[], unsigned int size, unsigned char value) +{ + for (unsigned int i = 0; i < size; ++i) { + if (data[i] != value) + return 0; + } + + return 1; +} + + unsigned int array_uint32_be (const unsigned char data[]) { diff --git a/src/array.h b/src/array.h index cc53dc2..2739e70 100644 --- a/src/array.h +++ b/src/array.h @@ -32,6 +32,9 @@ array_reverse_bytes (unsigned char data[], unsigned int size); void array_reverse_bits (unsigned char data[], unsigned int size); +int +array_isequal (const unsigned char data[], unsigned int size, unsigned char value); + unsigned int array_uint32_be (const unsigned char data[]); diff --git a/src/oceanic_common.c b/src/oceanic_common.c index 0d17f64..2307bee 100644 --- a/src/oceanic_common.c +++ b/src/oceanic_common.c @@ -306,6 +306,17 @@ oceanic_common_device_foreach (oceanic_common_device_t *device, const oceanic_co // Move to the start of the current entry. current -= PAGESIZE / 2; + // Check for uninitialized entries. Normally, such entries are + // never present, except when the ringbuffer is actually empty, + // but the ringbuffer pointers are not set to their empty values. + // This appears to happen on some devices, and we attempt to + // fix this here. + if (array_isequal (logbooks + current, PAGESIZE / 2, 0xFF)) { + begin = current + PAGESIZE / 2; + abort = 1; + break; + } + // Compare the fingerprint to identify previously downloaded entries. if (memcmp (logbooks + current, device->fingerprint, PAGESIZE / 2) == 0) { begin = current + PAGESIZE / 2;