--- src/cochran_commander.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/src/cochran_commander.c b/src/cochran_commander.c index 3ba3786..8bb61c9 100644 --- a/src/cochran_commander.c +++ b/src/cochran_commander.c @@ -22,6 +22,7 @@ #include <string.h> // memcpy, memcmp #include <stdlib.h> // malloc, free #include <assert.h> // assert +#include <stdio.h> // DEBUG JVO
#include <libdivecomputer/cochran.h>
@@ -632,7 +633,7 @@ cochran_get_sample_parms(dc_device_t *abstract) pre_dive_offset = array_uint32_le (&(d->logbook[i * layout->rb_log_size + layout->pt_log_profile_pre])); end_dive_offset = array_uint32_le (&(d->logbook[i * layout->rb_log_size - + layout->pt_log_profile_begin])); + + layout->pt_log_profile_end]));
// Check for ring buffer wrap-around. if (pre_dive_offset > end_dive_offset) @@ -678,7 +679,7 @@ cochran_read_samples(dc_device_t *abstract, dc_event_progress_t *progress) free(d->sample);
d->sample = (unsigned char *) malloc(d->sample_size); - if (device == NULL) { + if (d->sample == NULL) { ERROR (abstract->context, "Failed to allocate memory."); return DC_STATUS_NOMEMORY; } @@ -864,7 +865,7 @@ cochran_commander_device_foreach (dc_device_t *abstract, dc_status_t rc;
unsigned char *log, *fingerprint, *sample, *dive; - int sample_size, dive_size; + unsigned int sample_size, dive_size;
rc = cochran_commander_device_read_all (abstract);
@@ -896,27 +897,27 @@ cochran_commander_device_foreach (dc_device_t *abstract,
// Build dive blob dive_size = COCHRAN_MODEL_SIZE + layout->rb_log_size + sample_size; - dive = malloc(dive_size); + dive = (unsigned char *) malloc(dive_size); if (dive == NULL) return DC_STATUS_NOMEMORY;
memcpy(dive, data->id + 0x3B, 8); // model string - memcpy(dive + COCHRAN_MODEL_SIZE, log, layout->rb_log_size); + memcpy(dive + COCHRAN_MODEL_SIZE, log, layout->rb_log_size); // log
+ // Copy profile data if (sample_start_address <= sample_end_address) { memcpy(dive + COCHRAN_MODEL_SIZE + layout->rb_log_size, sample, sample_size); } else { // It wrapped the buffer, copy two sections - unsigned int size = layout->rb_profile_end - - sample_start_address; + unsigned int size = layout->rb_profile_end - sample_start_address; memcpy(dive + COCHRAN_MODEL_SIZE + layout->rb_log_size, sample, size); memcpy(dive + COCHRAN_MODEL_SIZE + layout->rb_log_size + size, data->sample, sample_size - size); }
- if (callback && !callback ((unsigned char *) dive, dive_size, - fingerprint, COCHRAN_FINGERPRINT_SIZE, userdata)) { + if (callback && !callback (dive, dive_size, fingerprint, + COCHRAN_FINGERPRINT_SIZE, userdata)) { free(dive); return DC_STATUS_SUCCESS; }