From 68380b2ec07b37338edf8d913c3a58a05310aee0 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Fri, 24 Nov 2017 20:58:21 +0100 Subject: [PATCH] Fix some casts with constant pointers Casting away the const qualifier generates a compiler warning which can easily be avoided by preserving the const qualifier. --- examples/output_xml.c | 2 +- src/bluetooth.c | 4 ++-- src/device.c | 6 +++--- src/irda.c | 4 ++-- src/oceanic_common.c | 2 +- src/serial_posix.c | 2 +- src/serial_win32.c | 2 +- src/suunto_common2.c | 2 +- src/usbhid.c | 2 +- 9 files changed, 13 insertions(+), 13 deletions(-) diff --git a/examples/output_xml.c b/examples/output_xml.c index 86a3957..bb88b2c 100644 --- a/examples/output_xml.c +++ b/examples/output_xml.c @@ -142,7 +142,7 @@ sample_cb (dc_sample_type_t type, dc_sample_value_t value, void *userdata) case DC_SAMPLE_VENDOR: fprintf (sampledata->ostream, " ", value.vendor.type, value.vendor.size); for (unsigned int i = 0; i < value.vendor.size; ++i) - fprintf (sampledata->ostream, "%02X", ((unsigned char *) value.vendor.data)[i]); + fprintf (sampledata->ostream, "%02X", ((const unsigned char *) value.vendor.data)[i]); fprintf (sampledata->ostream, "\n"); break; case DC_SAMPLE_SETPOINT: diff --git a/src/bluetooth.c b/src/bluetooth.c index bc9ffe0..01a3e96 100644 --- a/src/bluetooth.c +++ b/src/bluetooth.c @@ -571,7 +571,7 @@ dc_bluetooth_write (dc_bluetooth_t *device, const void *data, size_t size, size_ break; // Timeout. } - s_ssize_t n = send (device->fd, (char*) data + nbytes, size - nbytes, 0); + s_ssize_t n = send (device->fd, (const char *) data + nbytes, size - nbytes, 0); if (n < 0) { s_errcode_t errcode = S_ERRNO; if (errcode == S_EINTR || errcode == S_EAGAIN) @@ -591,7 +591,7 @@ dc_bluetooth_write (dc_bluetooth_t *device, const void *data, size_t size, size_ } out: - HEXDUMP (device->context, DC_LOGLEVEL_INFO, "Write", (unsigned char *) data, nbytes); + HEXDUMP (device->context, DC_LOGLEVEL_INFO, "Write", (const unsigned char *) data, nbytes); out_invalidargs: if (actual) diff --git a/src/device.c b/src/device.c index 266007a..aba42d5 100644 --- a/src/device.c +++ b/src/device.c @@ -408,7 +408,7 @@ dc_device_close (dc_device_t *device) void device_event_emit (dc_device_t *device, dc_event_type_t event, const void *data) { - dc_event_progress_t *progress = (dc_event_progress_t *) data; + const dc_event_progress_t *progress = (const dc_event_progress_t *) data; // Check the event data for errors. switch (event) { @@ -436,10 +436,10 @@ device_event_emit (dc_device_t *device, dc_event_type_t event, const void *data) // Cache the event data. switch (event) { case DC_EVENT_DEVINFO: - device->devinfo = *(dc_event_devinfo_t *) data; + device->devinfo = *(const dc_event_devinfo_t *) data; break; case DC_EVENT_CLOCK: - device->clock = *(dc_event_clock_t *) data; + device->clock = *(const dc_event_clock_t *) data; break; default: break; diff --git a/src/irda.c b/src/irda.c index d085ec0..1a2c38c 100644 --- a/src/irda.c +++ b/src/irda.c @@ -535,7 +535,7 @@ dc_irda_write (dc_irda_t *device, const void *data, size_t size, size_t *actual) break; // Timeout. } - s_ssize_t n = send (device->fd, (char*) data + nbytes, size - nbytes, 0); + s_ssize_t n = send (device->fd, (const char *) data + nbytes, size - nbytes, 0); if (n < 0) { s_errcode_t errcode = S_ERRNO; if (errcode == S_EINTR || errcode == S_EAGAIN) @@ -555,7 +555,7 @@ dc_irda_write (dc_irda_t *device, const void *data, size_t size, size_t *actual) } out: - HEXDUMP (device->context, DC_LOGLEVEL_INFO, "Write", (unsigned char *) data, nbytes); + HEXDUMP (device->context, DC_LOGLEVEL_INFO, "Write", (const unsigned char *) data, nbytes); out_invalidargs: if (actual) diff --git a/src/oceanic_common.c b/src/oceanic_common.c index 427b326..43bc06d 100644 --- a/src/oceanic_common.c +++ b/src/oceanic_common.c @@ -30,7 +30,7 @@ #include "rbstream.h" #include "array.h" -#define VTABLE(abstract) ((oceanic_common_device_vtable_t *) abstract->vtable) +#define VTABLE(abstract) ((const oceanic_common_device_vtable_t *) abstract->vtable) #define RB_LOGBOOK_DISTANCE(a,b,l) ringbuffer_distance (a, b, 0, l->rb_logbook_begin, l->rb_logbook_end) #define RB_LOGBOOK_INCR(a,b,l) ringbuffer_increment (a, b, l->rb_logbook_begin, l->rb_logbook_end) diff --git a/src/serial_posix.c b/src/serial_posix.c index 1a1567c..79fadeb 100644 --- a/src/serial_posix.c +++ b/src/serial_posix.c @@ -753,7 +753,7 @@ dc_serial_write (dc_serial_t *device, const void *data, size_t size, size_t *act } out: - HEXDUMP (device->context, DC_LOGLEVEL_INFO, "Write", (unsigned char *) data, nbytes); + HEXDUMP (device->context, DC_LOGLEVEL_INFO, "Write", (const unsigned char *) data, nbytes); out_invalidargs: if (actual) diff --git a/src/serial_win32.c b/src/serial_win32.c index bba78f8..c6f87f0 100644 --- a/src/serial_win32.c +++ b/src/serial_win32.c @@ -500,7 +500,7 @@ dc_serial_write (dc_serial_t *device, const void *data, size_t size, size_t *act } out: - HEXDUMP (device->context, DC_LOGLEVEL_INFO, "Write", (unsigned char *) data, dwWritten); + HEXDUMP (device->context, DC_LOGLEVEL_INFO, "Write", (const unsigned char *) data, dwWritten); out_invalidargs: if (actual) diff --git a/src/suunto_common2.c b/src/suunto_common2.c index 80b2477..4aa1699 100644 --- a/src/suunto_common2.c +++ b/src/suunto_common2.c @@ -38,7 +38,7 @@ #define RB_PROFILE_DISTANCE(l,a,b,m) ringbuffer_distance (a, b, m, l->rb_profile_begin, l->rb_profile_end) -#define VTABLE(abstract) ((suunto_common2_device_vtable_t *) abstract->vtable) +#define VTABLE(abstract) ((const suunto_common2_device_vtable_t *) abstract->vtable) void suunto_common2_device_init (suunto_common2_device_t *device) diff --git a/src/usbhid.c b/src/usbhid.c index f0c10df..0dff237 100644 --- a/src/usbhid.c +++ b/src/usbhid.c @@ -523,7 +523,7 @@ out: } #endif - HEXDUMP (usbhid->context, DC_LOGLEVEL_INFO, "Write", (unsigned char *) data, nbytes); + HEXDUMP (usbhid->context, DC_LOGLEVEL_INFO, "Write", (const unsigned char *) data, nbytes); out_invalidargs: if (actual)