Remove extra padding from the end of the profile

Even after removing the pages padded with 0xFF bytes, there are still
some invalid sample pages present at the end of the profile. But it
turns out the number of valid profile pages is stored in the logbook
entry.

The only caveat is that the number of pages appears to be stored as a 12
bit number, which limits the total profile size to only 64Kb. We don't
known what happens for larger dives.
This commit is contained in:
Janice McLaughlin 2018-09-25 20:03:18 +02:00 committed by Jef Driesen
parent e968f84999
commit a2100843b9

View File

@ -496,9 +496,13 @@ oceanic_common_device_profile (dc_device_t *abstract, dc_event_progress_t *progr
// Remove padding from the profile.
if (layout->highmem) {
unsigned char *profile = profiles + offset + layout->rb_logbook_entry_size;
while (rb_entry_size >= PAGESIZE && array_isequal (profile + rb_entry_size - PAGESIZE, PAGESIZE, 0xFF)) {
rb_entry_size -= PAGESIZE;
// The logbook entry contains the total number of pages containing
// profile data, excluding the footer page. Limit the profile size
// to this size.
unsigned int npages = (array_uint16_le (profiles + offset + 12) & 0x0FFF) + 1;
unsigned int length = npages * PAGESIZE;
if (rb_entry_size > length) {
rb_entry_size = length;
}
}