Validate the parameter before calling the vtable function

This removes the need to validate the date/time pointer in every single
backend.
This commit is contained in:
Jef Driesen 2022-12-18 11:16:01 +01:00
parent f4fae1b9f6
commit 9019805f52
8 changed files with 5 additions and 27 deletions

View File

@ -408,7 +408,7 @@ deepsix_excursion_device_timesync (dc_device_t *abstract, const dc_datetime_t *d
dc_status_t status = DC_STATUS_SUCCESS;
deepsix_excursion_device_t *device = (deepsix_excursion_device_t *) abstract;
if (datetime == NULL || datetime->year < 2000) {
if (datetime->year < 2000) {
ERROR (abstract->context, "Invalid date/time value specified.");
return DC_STATUS_INVALIDARGS;
}

View File

@ -404,6 +404,9 @@ dc_device_timesync (dc_device_t *device, const dc_datetime_t *datetime)
if (device->vtable->timesync == NULL)
return DC_STATUS_UNSUPPORTED;
if (datetime == NULL)
return DC_STATUS_INVALIDARGS;
return device->vtable->timesync (device, datetime);
}

View File

@ -608,11 +608,6 @@ divesystem_idive_device_timesync (dc_device_t *abstract, const dc_datetime_t *da
return DC_STATUS_UNSUPPORTED;
}
if (datetime == NULL) {
ERROR (abstract->context, "Invalid parameter specified.");
return DC_STATUS_INVALIDARGS;
}
// Get the UTC timestamp.
dc_ticks_t timestamp = dc_datetime_mktime(datetime);
if (timestamp == -1) {

View File

@ -473,11 +473,6 @@ hw_frog_device_timesync (dc_device_t *abstract, const dc_datetime_t *datetime)
{
hw_frog_device_t *device = (hw_frog_device_t *) abstract;
if (datetime == NULL) {
ERROR (abstract->context, "Invalid parameter specified.");
return DC_STATUS_INVALIDARGS;
}
// Send the command.
unsigned char packet[6] = {
datetime->hour, datetime->minute, datetime->second,

View File

@ -348,11 +348,6 @@ hw_ostc_device_timesync (dc_device_t *abstract, const dc_datetime_t *datetime)
dc_status_t status = DC_STATUS_SUCCESS;
hw_ostc_device_t *device = (hw_ostc_device_t *) abstract;
if (datetime == NULL) {
ERROR (abstract->context, "Invalid parameter specified.");
return DC_STATUS_INVALIDARGS;
}
// Send the command.
dc_status_t rc = hw_ostc_send (device, 'b', 1);
if (rc != DC_STATUS_SUCCESS)

View File

@ -938,11 +938,6 @@ hw_ostc3_device_timesync (dc_device_t *abstract, const dc_datetime_t *datetime)
{
hw_ostc3_device_t *device = (hw_ostc3_device_t *) abstract;
if (datetime == NULL) {
ERROR (abstract->context, "Invalid parameter specified.");
return DC_STATUS_INVALIDARGS;
}
dc_status_t rc = hw_ostc3_device_init (device, DOWNLOAD);
if (rc != DC_STATUS_SUCCESS)
return rc;

View File

@ -471,11 +471,6 @@ mclean_extreme_device_timesync(dc_device_t *abstract, const dc_datetime_t *datet
{
mclean_extreme_device_t *device = (mclean_extreme_device_t *)abstract;
if (datetime == NULL) {
ERROR(abstract->context, "Invalid parameter specified.");
return DC_STATUS_INVALIDARGS;
}
// Get the UTC timestamp.
dc_ticks_t ticks = dc_datetime_mktime(datetime);
if (ticks == -1 || ticks < EPOCH || ticks - EPOCH > 0xFFFFFFFF) {

View File

@ -461,7 +461,7 @@ sporasub_sp2_device_timesync (dc_device_t *abstract, const dc_datetime_t *dateti
dc_status_t status = DC_STATUS_SUCCESS;
sporasub_sp2_device_t *device = (sporasub_sp2_device_t *) abstract;
if (datetime == NULL || datetime->year < 2000) {
if (datetime->year < 2000) {
ERROR (abstract->context, "Invalid parameter specified.");
return DC_STATUS_INVALIDARGS;
}