From 9019805f52ff56b0f45b4aa95bfbb020633134f3 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Sun, 18 Dec 2022 11:16:01 +0100 Subject: [PATCH] Validate the parameter before calling the vtable function This removes the need to validate the date/time pointer in every single backend. --- src/deepsix_excursion.c | 2 +- src/device.c | 3 +++ src/divesystem_idive.c | 5 ----- src/hw_frog.c | 5 ----- src/hw_ostc.c | 5 ----- src/hw_ostc3.c | 5 ----- src/mclean_extreme.c | 5 ----- src/sporasub_sp2.c | 2 +- 8 files changed, 5 insertions(+), 27 deletions(-) diff --git a/src/deepsix_excursion.c b/src/deepsix_excursion.c index 2ee02eb..c6eaaa8 100644 --- a/src/deepsix_excursion.c +++ b/src/deepsix_excursion.c @@ -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; } diff --git a/src/device.c b/src/device.c index 3080e6a..66944b8 100644 --- a/src/device.c +++ b/src/device.c @@ -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); } diff --git a/src/divesystem_idive.c b/src/divesystem_idive.c index 61ec469..0410cd2 100644 --- a/src/divesystem_idive.c +++ b/src/divesystem_idive.c @@ -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) { diff --git a/src/hw_frog.c b/src/hw_frog.c index 74fc170..f98523b 100644 --- a/src/hw_frog.c +++ b/src/hw_frog.c @@ -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, diff --git a/src/hw_ostc.c b/src/hw_ostc.c index 7017321..6fdc6eb 100644 --- a/src/hw_ostc.c +++ b/src/hw_ostc.c @@ -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) diff --git a/src/hw_ostc3.c b/src/hw_ostc3.c index 07b7d8f..550bf7c 100644 --- a/src/hw_ostc3.c +++ b/src/hw_ostc3.c @@ -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; diff --git a/src/mclean_extreme.c b/src/mclean_extreme.c index b69546f..98038ff 100644 --- a/src/mclean_extreme.c +++ b/src/mclean_extreme.c @@ -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) { diff --git a/src/sporasub_sp2.c b/src/sporasub_sp2.c index 8112305..8be2e8a 100644 --- a/src/sporasub_sp2.c +++ b/src/sporasub_sp2.c @@ -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; }