Merge branch 'master' of git://github.com/libdivecomputer/libdivecomputer into Subsurface-NG
Merge with misc fixes upstream. This fixes a couple of small error cases. * 'master' of git://github.com/libdivecomputer/libdivecomputer: Don't pass a NULL pointer to memcpy Fix an uninitialized variable
This commit is contained in:
commit
8f4945dc1e
@ -117,7 +117,9 @@ tecdiving_divecomputereu_send (tecdiving_divecomputereu_device_t *device, unsign
|
|||||||
(size >> 24) & 0xFF,
|
(size >> 24) & 0xFF,
|
||||||
cmd,
|
cmd,
|
||||||
};
|
};
|
||||||
memcpy(packet + 7, data, size);
|
if (size) {
|
||||||
|
memcpy(packet + 7, data, size);
|
||||||
|
}
|
||||||
crc = checksum_crc (packet + 1, size + 6, 0);
|
crc = checksum_crc (packet + 1, size + 6, 0);
|
||||||
packet[size + 7] = (crc >> 8) & 0xFF;
|
packet[size + 7] = (crc >> 8) & 0xFF;
|
||||||
packet[size + 8] = (crc ) & 0xFF;
|
packet[size + 8] = (crc ) & 0xFF;
|
||||||
@ -463,27 +465,27 @@ tecdiving_divecomputereu_device_foreach (dc_device_t *abstract, dc_dive_callback
|
|||||||
status = tecdiving_divecomputereu_send (device, CMD_LIST, NULL, 0);
|
status = tecdiving_divecomputereu_send (device, CMD_LIST, NULL, 0);
|
||||||
if (status != DC_STATUS_SUCCESS) {
|
if (status != DC_STATUS_SUCCESS) {
|
||||||
ERROR (abstract->context, "Failed to send the list command.");
|
ERROR (abstract->context, "Failed to send the list command.");
|
||||||
goto error_free;
|
goto error_logbook_free;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read the dive list.
|
// Read the dive list.
|
||||||
status = tecdiving_divecomputereu_receive (device, RSP_LIST, logbook, length, &length);
|
status = tecdiving_divecomputereu_receive (device, RSP_LIST, logbook, length, &length);
|
||||||
if (status != DC_STATUS_SUCCESS) {
|
if (status != DC_STATUS_SUCCESS) {
|
||||||
ERROR (abstract->context, "Failed to receive the logbook.");
|
ERROR (abstract->context, "Failed to receive the logbook.");
|
||||||
goto error_free;
|
goto error_logbook_free;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify the minimum length.
|
// Verify the minimum length.
|
||||||
if (length < 2) {
|
if (length < 2) {
|
||||||
status = DC_STATUS_DATAFORMAT;
|
status = DC_STATUS_DATAFORMAT;
|
||||||
goto error_free;
|
goto error_logbook_free;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the number of logbook entries.
|
// Get the number of logbook entries.
|
||||||
unsigned int nlogbooks = array_uint16_be (logbook);
|
unsigned int nlogbooks = array_uint16_be (logbook);
|
||||||
if (length != 2 + nlogbooks * SZ_SUMMARY) {
|
if (length != 2 + nlogbooks * SZ_SUMMARY) {
|
||||||
status = DC_STATUS_DATAFORMAT;
|
status = DC_STATUS_DATAFORMAT;
|
||||||
goto error_free;
|
goto error_logbook_free;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Count the number of dives to download.
|
// Count the number of dives to download.
|
||||||
@ -506,7 +508,7 @@ tecdiving_divecomputereu_device_foreach (dc_device_t *abstract, dc_dive_callback
|
|||||||
dc_buffer_t *buffer = dc_buffer_new(0);
|
dc_buffer_t *buffer = dc_buffer_new(0);
|
||||||
if (buffer == NULL) {
|
if (buffer == NULL) {
|
||||||
status = DC_STATUS_NOMEMORY;
|
status = DC_STATUS_NOMEMORY;
|
||||||
goto error_free;
|
goto error_logbook_free;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned int i = 0; i < ndives; ++i) {
|
for (unsigned int i = 0; i < ndives; ++i) {
|
||||||
@ -515,7 +517,7 @@ tecdiving_divecomputereu_device_foreach (dc_device_t *abstract, dc_dive_callback
|
|||||||
// Read the dive.
|
// Read the dive.
|
||||||
status = tecdiving_divecomputereu_readdive (abstract, &progress, i, buffer);
|
status = tecdiving_divecomputereu_readdive (abstract, &progress, i, buffer);
|
||||||
if (status != DC_STATUS_SUCCESS) {
|
if (status != DC_STATUS_SUCCESS) {
|
||||||
goto error_free;
|
goto error_buffer_free;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cache the pointer.
|
// Cache the pointer.
|
||||||
@ -526,7 +528,7 @@ tecdiving_divecomputereu_device_foreach (dc_device_t *abstract, dc_dive_callback
|
|||||||
if (memcmp (data, logbook + offset, SZ_SUMMARY) != 0) {
|
if (memcmp (data, logbook + offset, SZ_SUMMARY) != 0) {
|
||||||
ERROR (abstract->context, "Dive header doesn't match logbook entry.");
|
ERROR (abstract->context, "Dive header doesn't match logbook entry.");
|
||||||
status = DC_STATUS_DATAFORMAT;
|
status = DC_STATUS_DATAFORMAT;
|
||||||
goto error_free;
|
goto error_buffer_free;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (callback && !callback (data, size, data, sizeof(device->fingerprint), userdata)) {
|
if (callback && !callback (data, size, data, sizeof(device->fingerprint), userdata)) {
|
||||||
@ -534,8 +536,9 @@ tecdiving_divecomputereu_device_foreach (dc_device_t *abstract, dc_dive_callback
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
error_free:
|
error_buffer_free:
|
||||||
dc_buffer_free (buffer);
|
dc_buffer_free (buffer);
|
||||||
|
error_logbook_free:
|
||||||
free (logbook);
|
free (logbook);
|
||||||
error_exit:
|
error_exit:
|
||||||
return status;
|
return status;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user