From e2848118bf7f680633bdab5e31ff6f3804bd14d8 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sun, 9 May 2021 14:33:32 -0700 Subject: clang-tidy: use C++ casting Found with google-readability-casting Signed-off-by: Rosen Penev --- server/char-device.cpp | 30 +++--- server/common-graphics-channel.cpp | 2 +- server/dcc-send.cpp | 13 +-- server/dcc.cpp | 49 ++++----- server/display-channel.cpp | 36 +++---- server/image-encoders.cpp | 7 +- server/inputs-channel.cpp | 20 ++-- server/main-channel-client.cpp | 14 +-- server/main-channel.cpp | 16 +-- server/main-dispatcher.cpp | 16 +-- server/memslot.c | 2 +- server/red-channel-client.cpp | 16 +-- server/red-channel.cpp | 2 +- server/red-parse-qxl.cpp | 112 +++++++++++---------- server/red-pipe-item.cpp | 2 +- server/red-qxl.cpp | 5 +- server/red-replay-qxl.cpp | 99 ++++++++++-------- server/red-stream-device.cpp | 38 +++---- server/red-stream.cpp | 22 ++-- server/red-worker.cpp | 22 ++-- server/reds.cpp | 196 ++++++++++++++++++------------------ server/sound.cpp | 40 ++++---- server/spicevmc.cpp | 37 +++---- server/stream-channel.cpp | 2 +- server/tests/test-channel.cpp | 8 +- server/tests/test-display-base.cpp | 29 +++--- server/tests/test-display-base.h | 3 +- server/tests/test-display-no-ssl.c | 2 +- server/tests/test-stream-device.cpp | 6 +- server/tests/test-two-servers.c | 2 +- server/tree.cpp | 6 +- server/video-stream.cpp | 23 +++-- 32 files changed, 453 insertions(+), 424 deletions(-) diff --git a/server/char-device.cpp b/server/char-device.cpp index 742e815d..1be96c06 100644 --- a/server/char-device.cpp +++ b/server/char-device.cpp @@ -114,7 +114,7 @@ static void red_char_device_write_buffer_free(RedCharDeviceWriteBuffer *buf) static void write_buffers_queue_free(GQueue *write_queue) { RedCharDeviceWriteBuffer *buf; - while ((buf = (RedCharDeviceWriteBuffer *) g_queue_pop_tail(write_queue))) + while ((buf = static_cast(g_queue_pop_tail(write_queue)))) red_char_device_write_buffer_free(buf); } @@ -132,7 +132,7 @@ static void red_char_device_client_free(RedCharDevice *dev, spice_debug("write_queue_is_empty %d", g_queue_is_empty(&dev->priv->write_queue) && !dev->priv->cur_write_buf); l = g_queue_peek_head_link(&dev->priv->write_queue); while (l) { - auto write_buf = (RedCharDeviceWriteBuffer *) l->data; + auto write_buf = static_cast(l->data); next = l->next; if (write_buf->priv->origin == WRITE_BUFFER_ORIGIN_CLIENT && @@ -394,7 +394,8 @@ int RedCharDevice::write_to_device() uint32_t write_len; if (!priv->cur_write_buf) { - priv->cur_write_buf = (RedCharDeviceWriteBuffer *) g_queue_pop_tail(&priv->write_queue); + priv->cur_write_buf = + static_cast(g_queue_pop_tail(&priv->write_queue)); if (!priv->cur_write_buf) break; priv->cur_write_buf_pos = priv->cur_write_buf->buf; @@ -457,8 +458,8 @@ red_char_device_write_buffer_get(RedCharDevice *dev, RedCharDeviceClientOpaque * RedCharDeviceWriteBufferPrivate priv; RedCharDeviceWriteBuffer buffer; } *write_buf; - write_buf = (struct RedCharDeviceWriteBufferFull* ) - g_malloc(sizeof(struct RedCharDeviceWriteBufferFull) + size); + write_buf = static_cast( + g_malloc(sizeof(struct RedCharDeviceWriteBufferFull) + size)); memset(write_buf, 0, sizeof(*write_buf)); write_buf->priv.refs = 1; ret = &write_buf->buffer; @@ -712,7 +713,7 @@ void RedCharDevice::reset() priv->wait_for_migrate_data = FALSE; spice_debug("char device %p", this); - while ((buf = (RedCharDeviceWriteBuffer *) g_queue_pop_tail(&priv->write_queue))) { + while ((buf = static_cast(g_queue_pop_tail(&priv->write_queue)))) { write_buffer_release(&buf); } write_buffer_release(&priv->cur_write_buf); @@ -745,8 +746,8 @@ void RedCharDevice::migrate_data_marshall_empty(SpiceMarshaller *m) SpiceMigrateDataCharDevice *mig_data; spice_debug("trace"); - mig_data = (SpiceMigrateDataCharDevice *)spice_marshaller_reserve_space(m, - sizeof(*mig_data)); + mig_data = reinterpret_cast( + spice_marshaller_reserve_space(m, sizeof(*mig_data))); memset(mig_data, 0, sizeof(*mig_data)); mig_data->version = SPICE_MIGRATE_DATA_CHAR_DEVICE_VERSION; mig_data->connected = FALSE; @@ -754,7 +755,7 @@ void RedCharDevice::migrate_data_marshall_empty(SpiceMarshaller *m) static void migrate_data_marshaller_write_buffer_free(uint8_t *data, void *opaque) { - auto write_buf = (RedCharDeviceWriteBuffer *)opaque; + auto write_buf = static_cast(opaque); red_char_device_write_buffer_unref(write_buf); } @@ -770,7 +771,7 @@ void RedCharDevice::migrate_data_marshall(SpiceMarshaller *m) /* multi-clients are not supported */ spice_assert(g_list_length(priv->clients) == 1); - dev_client = (RedCharDeviceClient *) g_list_last(priv->clients)->data; + dev_client = static_cast(g_list_last(priv->clients)->data); /* FIXME: if there were more than one client before the marshalling, * it is possible that the send_queue length > 0, and the send data * should be migrated as well */ @@ -799,7 +800,7 @@ void RedCharDevice::migrate_data_marshall(SpiceMarshaller *m) } for (item = g_queue_peek_tail_link(&priv->write_queue); item != nullptr; item = item->prev) { - auto write_buf = (RedCharDeviceWriteBuffer *) item->data; + auto write_buf = static_cast(item->data); spice_marshaller_add_by_ref_full(m2, write_buf->buf, write_buf->buf_used, migrate_data_marshaller_write_buffer_free, @@ -825,7 +826,7 @@ bool RedCharDevice::restore(SpiceMigrateDataCharDevice *mig_data) spice_assert(g_list_length(priv->clients) == 1 && priv->wait_for_migrate_data); - dev_client = (RedCharDeviceClient *) g_list_last(priv->clients)->data; + dev_client = static_cast(g_list_last(priv->clients)->data); if (mig_data->version > SPICE_MIGRATE_DATA_CHAR_DEVICE_VERSION) { spice_error("dev %p error: migration data version %u is bigger than self %u", this, mig_data->version, SPICE_MIGRATE_DATA_CHAR_DEVICE_VERSION); @@ -855,7 +856,8 @@ bool RedCharDevice::restore(SpiceMigrateDataCharDevice *mig_data) } /* the first write buffer contains all the data that was saved for migration */ memcpy(priv->cur_write_buf->buf, - ((uint8_t *)mig_data) + mig_data->write_data_ptr - sizeof(SpiceMigrateDataHeader), + (reinterpret_cast(mig_data)) + mig_data->write_data_ptr - + sizeof(SpiceMigrateDataHeader), mig_data->write_size); priv->cur_write_buf->buf_used = mig_data->write_size; priv->cur_write_buf_pos = priv->cur_write_buf->buf; @@ -914,7 +916,7 @@ RedCharDevice::~RedCharDevice() priv->cur_write_buf = nullptr; while (priv->clients != nullptr) { - auto dev_client = (RedCharDeviceClient *) priv->clients->data; + auto dev_client = static_cast(priv->clients->data); red_char_device_client_free(this, dev_client); } priv->running = FALSE; diff --git a/server/common-graphics-channel.cpp b/server/common-graphics-channel.cpp index 7f6e5a90..f9ba511b 100644 --- a/server/common-graphics-channel.cpp +++ b/server/common-graphics-channel.cpp @@ -26,7 +26,7 @@ uint8_t *CommonGraphicsChannelClient::alloc_recv_buf(uint16_t type, uint32_t siz { /* SPICE_MSGC_MIGRATE_DATA is the only client message whose size is dynamic */ if (type == SPICE_MSGC_MIGRATE_DATA) { - return (uint8_t *) g_malloc(size); + return static_cast(g_malloc(size)); } if (size > sizeof(recv_buf)) { diff --git a/server/dcc-send.cpp b/server/dcc-send.cpp index f61faeab..2c40a231 100644 --- a/server/dcc-send.cpp +++ b/server/dcc-send.cpp @@ -327,7 +327,7 @@ static void fill_base(SpiceMarshaller *base_marshaller, Drawable *drawable) static void marshaller_compress_buf_free(uint8_t *data, void *opaque) { - compress_buf_free((RedCompressBuf*) opaque); + compress_buf_free(static_cast(opaque)); } static void marshaller_add_compressed(SpiceMarshaller *m, @@ -347,7 +347,7 @@ static void marshaller_add_compressed(SpiceMarshaller *m, static void marshaller_unref_drawable(uint8_t *data, void *opaque) { - auto drawable = (Drawable *) opaque; + auto drawable = static_cast(opaque); drawable_unref(drawable); } @@ -1633,7 +1633,7 @@ static void red_lossy_marshall_qxl_draw_text(DisplayChannelClient *dcc, static void red_release_video_encoder_buffer(uint8_t *data, void *opaque) { - auto buffer = (VideoBuffer*)opaque; + auto buffer = static_cast(opaque); buffer->free(buffer); } @@ -1804,8 +1804,8 @@ static void display_channel_marshall_migrate_data(DisplayChannelClient *dcc, display_data.glz_dict_data = glz_dict_data; /* all data besided the surfaces ref */ - spice_marshaller_add(base_marshaller, - (uint8_t *)&display_data, sizeof(display_data) - sizeof(uint32_t)); + spice_marshaller_add(base_marshaller, reinterpret_cast(&display_data), + sizeof(display_data) - sizeof(uint32_t)); display_channel_marshall_migrate_data_surfaces(dcc, base_marshaller, display_channel->priv->enable_jpeg); } @@ -2223,7 +2223,8 @@ static void marshall_monitors_config(RedChannelClient *rcc, SpiceMarshaller *bas { int heads_size = sizeof(SpiceHead) * monitors_config->count; int i; - auto msg = (SpiceMsgDisplayMonitorsConfig *) g_malloc0(sizeof(SpiceMsgDisplayMonitorsConfig) + heads_size); + auto msg = static_cast( + g_malloc0(sizeof(SpiceMsgDisplayMonitorsConfig) + heads_size)); int count = 0; // ignore monitors_config->count, it may contain zero width monitors, remove them now rcc->init_send_data(SPICE_MSG_DISPLAY_MONITORS_CONFIG); diff --git a/server/dcc.cpp b/server/dcc.cpp index 094e0860..01c16ab7 100644 --- a/server/dcc.cpp +++ b/server/dcc.cpp @@ -46,9 +46,8 @@ DisplayChannelClient::DisplayChannelClient(DisplayChannel *display, // todo: tune quality according to bandwidth priv->encoders.jpeg_quality = 85; - priv->send_data.free_list.res = (SpiceResourceList*) - g_malloc(sizeof(SpiceResourceList) + - DISPLAY_FREE_LIST_DEFAULT_SIZE * sizeof(SpiceResourceID)); + priv->send_data.free_list.res = static_cast(g_malloc( + sizeof(SpiceResourceList) + DISPLAY_FREE_LIST_DEFAULT_SIZE * sizeof(SpiceResourceID))); priv->send_data.free_list.res_size = DISPLAY_FREE_LIST_DEFAULT_SIZE; @@ -89,7 +88,7 @@ bool dcc_drawable_is_in_pipe(DisplayChannelClient *dcc, Drawable *drawable) GList *l; for (l = drawable->pipes; l != nullptr; l = l->next) { - dpi = (RedDrawablePipeItem *) l->data; + dpi = static_cast(l->data); if (dpi->dcc == dcc) { return TRUE; } @@ -512,7 +511,7 @@ XXX_CAST(RedChannelClient, DisplayChannelClient, DISPLAY_CHANNEL_CLIENT); RedPipeItemPtr dcc_gl_draw_item_new(RedChannelClient *rcc, void *data, int num) { DisplayChannelClient *dcc = DISPLAY_CHANNEL_CLIENT(rcc); - auto draw = (const SpiceMsgDisplayGlDraw *) data; + auto draw = static_cast(data); if (!red_stream_is_plain_unix(rcc->get_stream()) || !rcc->test_remote_cap(SPICE_DISPLAY_CAP_GL_SCANOUT)) { @@ -688,7 +687,7 @@ lz_compress: } if (!success) { - uint64_t image_size = src->stride * (uint64_t)src->y; + uint64_t image_size = src->stride * uint64_t{src->y}; stat_compress_add(&display_channel->priv->encoder_shared_data.off_stat, start_time, image_size, image_size); } @@ -732,9 +731,9 @@ static void dcc_push_release(DisplayChannelClient *dcc, uint8_t type, uint64_t i } if (free_list->res->count == free_list->res_size) { - free_list->res = (SpiceResourceList*) g_realloc(free_list->res, - sizeof(*free_list->res) + - free_list->res_size * sizeof(SpiceResourceID) * 2); + free_list->res = static_cast( + g_realloc(free_list->res, + sizeof(*free_list->res) + free_list->res_size * sizeof(SpiceResourceID) * 2)); free_list->res_size *= 2; } free_list->res->resources[free_list->res->count].type = type; @@ -885,7 +884,7 @@ static bool dcc_handle_preferred_compression(DisplayChannelClient *dcc, case SPICE_IMAGE_COMPRESSION_LZ: case SPICE_IMAGE_COMPRESSION_GLZ: case SPICE_IMAGE_COMPRESSION_OFF: - dcc->priv->image_compression = (SpiceImageCompression) pc->image_compression; + dcc->priv->image_compression = static_cast(pc->image_compression); break; default: spice_warning("preferred-compression: unsupported image compression setting"); @@ -908,9 +907,9 @@ static gint sort_video_codecs_by_client_preference(gconstpointer a_pointer, gconstpointer b_pointer, gpointer user_data) { - auto a = (const RedVideoCodec *) a_pointer; - auto b = (const RedVideoCodec *) b_pointer; - auto client_pref = (GArray *) user_data; + auto a = static_cast(a_pointer); + auto b = static_cast(b_pointer); + auto client_pref = static_cast(user_data); return (g_array_index(client_pref, gint, a->type) - g_array_index(client_pref, gint, b->type)); @@ -994,17 +993,17 @@ bool DisplayChannelClient::handle_message(uint16_t type, uint32_t size, void *ms { switch (type) { case SPICE_MSGC_DISPLAY_INIT: - return dcc_handle_init(this, (SpiceMsgcDisplayInit *)msg); + return dcc_handle_init(this, static_cast(msg)); case SPICE_MSGC_DISPLAY_STREAM_REPORT: - return dcc_handle_stream_report(this, (SpiceMsgcDisplayStreamReport *)msg); + return dcc_handle_stream_report(this, static_cast(msg)); case SPICE_MSGC_DISPLAY_PREFERRED_COMPRESSION: - return dcc_handle_preferred_compression(this, - (SpiceMsgcDisplayPreferredCompression *)msg); + return dcc_handle_preferred_compression( + this, static_cast(msg)); case SPICE_MSGC_DISPLAY_GL_DRAW_DONE: return dcc_handle_gl_draw_done(this); case SPICE_MSGC_DISPLAY_PREFERRED_VIDEO_CODEC_TYPE: - return dcc_handle_preferred_video_codec_type(this, - (SpiceMsgcDisplayPreferredVideoCodecType *)msg); + return dcc_handle_preferred_video_codec_type( + this, static_cast(msg)); default: return RedChannelClient::handle_message(type, size, msg); } @@ -1077,8 +1076,8 @@ bool DisplayChannelClient::handle_migrate_data(uint32_t size, void *message) DisplayChannelClient *dcc = this; DisplayChannel *display = DCC_TO_DC(dcc); int surfaces_restored = FALSE; - auto header = (SpiceMigrateDataHeader *)message; - auto migrate_data = (SpiceMigrateDataDisplay *)(header + 1); + auto header = static_cast(message); + auto migrate_data = reinterpret_cast(header + 1); uint8_t *surfaces; int i; @@ -1128,10 +1127,12 @@ bool DisplayChannelClient::handle_migrate_data(uint32_t size, void *message) } } - surfaces = (uint8_t *)message + migrate_data->surfaces_at_client_ptr; + surfaces = static_cast(message) + migrate_data->surfaces_at_client_ptr; surfaces_restored = display->priv->enable_jpeg ? - restore_surfaces_lossy(dcc, (MigrateDisplaySurfacesAtClientLossy *)surfaces) : - restore_surfaces_lossless(dcc, (MigrateDisplaySurfacesAtClientLossless*)surfaces); + restore_surfaces_lossy(dcc, + reinterpret_cast(surfaces)) : + restore_surfaces_lossless(dcc, + reinterpret_cast(surfaces)); spice_return_val_if_fail(surfaces_restored, FALSE); diff --git a/server/display-channel.cpp b/server/display-channel.cpp index c3affb01..4bd0cf41 100644 --- a/server/display-channel.cpp +++ b/server/display-channel.cpp @@ -126,7 +126,7 @@ static MonitorsConfig* monitors_config_new(const QXLHead *heads, ssize_t nheads, { MonitorsConfig *mc; - mc = (MonitorsConfig*) g_malloc(sizeof(MonitorsConfig) + nheads * sizeof(QXLHead)); + mc = static_cast(g_malloc(sizeof(MonitorsConfig) + nheads * sizeof(QXLHead))); mc->refs = 1; mc->count = nheads; mc->max_allowed = max; @@ -319,7 +319,7 @@ static void pipes_add_drawable_after(DisplayChannel *display, int num_other_linked = 0; for (GList *l = pos_after->pipes; l != nullptr; l = l->next) { - dpi_pos_after = (RedDrawablePipeItem*) l->data; + dpi_pos_after = static_cast(l->data); num_other_linked++; dcc_add_drawable_after(dpi_pos_after->dcc, drawable, dpi_pos_after); @@ -334,7 +334,7 @@ static void pipes_add_drawable_after(DisplayChannel *display, FOREACH_DCC(display, dcc) { int sent = 0; for (GList *l = pos_after->pipes; l != nullptr; l = l->next) { - dpi_pos_after = (RedDrawablePipeItem*) l->data; + dpi_pos_after = static_cast(l->data); if (dpi_pos_after->dcc == dcc) { sent = 1; break; @@ -514,7 +514,7 @@ static bool current_add_equal(DisplayChannel *display, DrawItem *item, TreeItem dpi_item = g_list_first(other_drawable->pipes); /* dpi contains a sublist of dcc's, ordered the same */ FOREACH_DCC(display, dcc) { - if (dpi_item && dcc == ((RedDrawablePipeItem *) dpi_item->data)->dcc) { + if (dpi_item && dcc == (static_cast(dpi_item->data))->dcc) { dpi_item = dpi_item->next; } else { dcc_prepend_drawable(dcc, drawable); @@ -747,7 +747,7 @@ static void exclude_region(DisplayChannel *display, Ring *ring, RingItem *ring_i /* the caller wanted to stop at this item, but this item * has been removed, so we set @last to the next item */ SPICE_VERIFY(SPICE_OFFSETOF(TreeItem, siblings_link) == 0); - *last = (TreeItem *)ring_next(ring, ring_item); + *last = reinterpret_cast(ring_next(ring, ring_item)); } } else if (now->type == TREE_ITEM_TYPE_CONTAINER) { /* if this sibling is a container type, descend into the @@ -774,7 +774,7 @@ static void exclude_region(DisplayChannel *display, Ring *ring, RingItem *ring_i SPICE_VERIFY(SPICE_OFFSETOF(TreeItem, siblings_link) == 0); /* if this is the last item to check, or if the current ring is * completed, don't go any further */ - while ((last && *last == (TreeItem *)ring_item) || + while ((last && *last == reinterpret_cast(ring_item)) || !(ring_item = ring_next(ring, ring_item))) { /* we're currently iterating the top ring, so we're done */ if (ring == top_ring) { @@ -1161,7 +1161,7 @@ static void handle_self_bitmap(DisplayChannel *display, Drawable *drawable) image->descriptor.height = image->u.bitmap.y = height; image->u.bitmap.palette = nullptr; - dest = (uint8_t *)spice_malloc_n(height, dest_stride); + dest = static_cast(spice_malloc_n(height, dest_stride)); image->u.bitmap.data = spice_chunks_new_linear(dest, height * dest_stride); image->u.bitmap.data->flags |= SPICE_CHUNKS_FLAGS_FREE; @@ -1394,7 +1394,7 @@ bool display_channel_wait_for_migrate_data(DisplayChannel *display) spice_debug("trace"); spice_warn_if_fail(g_list_length(clients) == 1); - rcc = (RedChannelClient*) g_list_nth_data(clients, 0); + rcc = static_cast(g_list_nth_data(clients, 0)); red::shared_ptr hold_rcc(rcc); for (;;) { @@ -1522,8 +1522,8 @@ static Drawable* drawable_try_new(DisplayChannel *display) static void drawable_free(DisplayChannel *display, Drawable *drawable) { drawable->~Drawable(); - ((_Drawable *)drawable)->u.next = display->priv->free_drawables; - display->priv->free_drawables = (_Drawable *)drawable; + reinterpret_cast<_Drawable *>(drawable)->u.next = display->priv->free_drawables; + display->priv->free_drawables = reinterpret_cast<_Drawable *>(drawable); display->priv->drawable_count--; } @@ -1784,7 +1784,7 @@ static void surface_update_dest(RedSurface *surface, const SpiceRect *area) { SpiceCanvas *canvas = surface->context.canvas; int stride = surface->context.stride; - auto line_0 = (uint8_t*) surface->context.line_0; + auto line_0 = static_cast(surface->context.line_0); if (surface->context.canvas_draws_on_surface) return; @@ -2049,9 +2049,10 @@ create_canvas_for_surface(DisplayChannel *display, RedSurface *surface, uint32_t switch (renderer) { case RED_RENDERER_SW: - canvas = canvas_create_for_data(surface->context.width, surface->context.height, surface->context.format, - (uint8_t*) surface->context.line_0, surface->context.stride, - &display->priv->image_cache.base, + canvas = canvas_create_for_data(surface->context.width, surface->context.height, + surface->context.format, + static_cast(surface->context.line_0), + surface->context.stride, &display->priv->image_cache.base, &display->priv->image_surfaces, nullptr, nullptr, nullptr); surface->context.top_down = TRUE; surface->context.canvas_draws_on_surface = TRUE; @@ -2079,7 +2080,7 @@ display_channel_create_surface(DisplayChannel *display, uint32_t surface_id, uin surface->context.stride = stride; surface->context.line_0 = line_0; if (!data_is_valid) { - auto data = (char*) line_0; + auto data = static_cast(line_0); if (stride < 0) { data -= abs(stride) * (height - 1); } @@ -2140,7 +2141,8 @@ bool DisplayChannelClient::handle_migrate_data_get_serial(uint32_t size, void *m { SpiceMigrateDataDisplay *migrate_data; - migrate_data = (SpiceMigrateDataDisplay *)((uint8_t *)message + sizeof(SpiceMigrateDataHeader)); + migrate_data = reinterpret_cast(static_cast(message) + + sizeof(SpiceMigrateDataHeader)); serial = migrate_data->message_serial; return true; @@ -2260,7 +2262,7 @@ void display_channel_process_surface_cmd(DisplayChannel *display, if (stride < 0) { /* No need to worry about overflow here, command should already be validated * when it is read, specifically red_get_surface_cmd */ - data -= (int32_t)(stride * (height - 1)); + data -= static_cast(stride * (height - 1)); } surface = display_channel_create_surface(display, surface_id, create->width, height, stride, create->format, data, diff --git a/server/image-encoders.cpp b/server/image-encoders.cpp index 4ebcb753..3b33bd81 100644 --- a/server/image-encoders.cpp +++ b/server/image-encoders.cpp @@ -234,7 +234,8 @@ static int encoder_usr_more_space(EncoderData *enc_data, uint8_t **io_ptr) static int quic_usr_more_space(QuicUsrContext *usr, uint32_t **io_ptr, int rows_completed) { EncoderData *usr_data = &(SPICE_CONTAINEROF(usr, QuicData, usr)->data); - return encoder_usr_more_space(usr_data, (uint8_t **)io_ptr) / sizeof(uint32_t); + return encoder_usr_more_space(usr_data, reinterpret_cast(io_ptr)) / + sizeof(uint32_t); } static int lz_usr_more_space(LzUsrContext *usr, uint8_t **io_ptr) @@ -387,7 +388,7 @@ static void image_encoders_init_lz(ImageEncoders *enc) static void glz_usr_free_image(GlzEncoderUsrContext *usr, GlzUsrImageContext *image) { GlzData *lz_data = SPICE_CONTAINEROF(usr, GlzData, usr); - auto glz_drawable_instance = (GlzDrawableInstanceItem *)image; + auto glz_drawable_instance = static_cast(image); ImageEncoders *drawable_enc = glz_drawable_instance->glz_drawable->encoders; ImageEncoders *this_enc = SPICE_CONTAINEROF(lz_data, ImageEncoders, glz_data); if (this_enc == drawable_enc) { @@ -709,7 +710,7 @@ static GlzSharedDictionary *find_glz_dictionary(RedClient *client, uint8_t dict_ GlzSharedDictionary *ret = nullptr; for (l = glz_dictionary_list; l != nullptr; l = l->next) { - auto dict = (GlzSharedDictionary *) l->data; + auto dict = static_cast(l->data); if ((dict->client == client) && (dict->id == dict_id)) { ret = dict; break; diff --git a/server/inputs-channel.cpp b/server/inputs-channel.cpp index bdab4cdc..029dad4a 100644 --- a/server/inputs-channel.cpp +++ b/server/inputs-channel.cpp @@ -246,12 +246,12 @@ bool InputsChannelClient::handle_message(uint16_t type, uint32_t size, void *mes switch (type) { case SPICE_MSGC_INPUTS_KEY_DOWN: { - auto key_down = (SpiceMsgcKeyDown *) message; + auto key_down = static_cast(message); inputs_channel->sync_locks(key_down->code); } /* fallthrough */ case SPICE_MSGC_INPUTS_KEY_UP: { - auto key_up = (SpiceMsgcKeyUp *) message; + auto key_up = static_cast(message); for (i = 0; i < 4; i++) { uint8_t code = (key_up->code >> (i * 8)) & 0xff; if (code == 0) { @@ -263,7 +263,7 @@ bool InputsChannelClient::handle_message(uint16_t type, uint32_t size, void *mes break; } case SPICE_MSGC_INPUTS_KEY_SCANCODE: { - auto code = (uint8_t *) message; + auto code = static_cast(message); for (i = 0; i < size; i++) { kbd_push_scan(inputs_channel->keyboard, code[i]); inputs_channel->sync_locks(code[i]); @@ -272,7 +272,7 @@ bool InputsChannelClient::handle_message(uint16_t type, uint32_t size, void *mes } case SPICE_MSGC_INPUTS_MOUSE_MOTION: { SpiceMouseInstance *mouse = inputs_channel->mouse; - auto mouse_motion = (SpiceMsgcMouseMotion *) message; + auto mouse_motion = static_cast(message); on_mouse_motion(); if (mouse && reds_get_mouse_mode(reds) == SPICE_MOUSE_MODE_SERVER) { @@ -285,7 +285,7 @@ bool InputsChannelClient::handle_message(uint16_t type, uint32_t size, void *mes break; } case SPICE_MSGC_INPUTS_MOUSE_POSITION: { - auto pos = (SpiceMsgcMousePosition *) message; + auto pos = static_cast(message); SpiceTabletInstance *tablet = inputs_channel->tablet; on_mouse_motion(); @@ -308,7 +308,7 @@ bool InputsChannelClient::handle_message(uint16_t type, uint32_t size, void *mes break; } case SPICE_MSGC_INPUTS_MOUSE_PRESS: { - auto mouse_press = (SpiceMsgcMousePress *) message; + auto mouse_press = static_cast(message); int dz = 0; if (mouse_press->button == SPICE_MOUSE_BUTTON_UP) { dz = -1; @@ -339,7 +339,7 @@ bool InputsChannelClient::handle_message(uint16_t type, uint32_t size, void *mes break; } case SPICE_MSGC_INPUTS_MOUSE_RELEASE: { - auto mouse_release = (SpiceMsgcMouseRelease *) message; + auto mouse_release = static_cast(message); if (reds_get_mouse_mode(reds) == SPICE_MOUSE_MODE_CLIENT) { if (reds_config_get_agent_mouse(reds) && reds_has_vdagent(reds)) { inputs_channel->mouse_state.buttons = @@ -362,7 +362,7 @@ bool InputsChannelClient::handle_message(uint16_t type, uint32_t size, void *mes break; } case SPICE_MSGC_INPUTS_KEY_MODIFIERS: { - auto modifiers = (SpiceMsgcKeyModifiers *) message; + auto modifiers = static_cast(message); uint8_t leds; SpiceKbdInstance *keyboard = inputs_channel->keyboard; @@ -495,8 +495,8 @@ bool InputsChannelClient::handle_migrate_data(uint32_t size, void *message) return FALSE; } - header = (SpiceMigrateDataHeader *)message; - mig_data = (SpiceMigrateDataInputs *)(header + 1); + header = static_cast(message); + mig_data = reinterpret_cast(header + 1); if (!migration_protocol_validate_header(header, SPICE_MIGRATE_DATA_INPUTS_MAGIC, diff --git a/server/main-channel-client.cpp b/server/main-channel-client.cpp index 054f100b..01600064 100644 --- a/server/main-channel-client.cpp +++ b/server/main-channel-client.cpp @@ -369,8 +369,8 @@ void MainChannelClient::handle_pong(SpiceMsgPing *ping, uint32_t size) start_connectivity_monitoring(CLIENT_CONNECTIVITY_TIMEOUT); break; } - priv->bitrate_per_sec = (uint64_t)(NET_TEST_BYTES * 8) * 1000000 - / (roundtrip - priv->latency); + priv->bitrate_per_sec = + uint64_t{NET_TEST_BYTES * 8} * 1000000 / (roundtrip - priv->latency); priv->net_test_stage = NET_TEST_STAGE_COMPLETE; red_channel_debug(get_channel(), "net test: latency %f ms, bitrate %" G_GUINT64_FORMAT " bps (%f Mbps)%s", @@ -666,7 +666,7 @@ static void main_channel_marshall_notify(RedChannelClient *rcc, notify.what = SPICE_WARN_GENERAL; notify.message_len = strlen(item->msg.get()); spice_marshall_msg_notify(m, ¬ify); - spice_marshaller_add(m, (uint8_t *)item->msg.get(), notify.message_len + 1); + spice_marshaller_add(m, reinterpret_cast(item->msg.get()), notify.message_len + 1); } static void main_channel_fill_migrate_dst_info(MainChannel *main_channel, @@ -676,10 +676,10 @@ static void main_channel_fill_migrate_dst_info(MainChannel *main_channel, dst_info->port = mig_dst->port; dst_info->sport = mig_dst->sport; dst_info->host_size = strlen(mig_dst->host) + 1; - dst_info->host_data = (uint8_t *)mig_dst->host; + dst_info->host_data = reinterpret_cast(mig_dst->host); if (mig_dst->cert_subject) { dst_info->cert_subject_size = strlen(mig_dst->cert_subject) + 1; - dst_info->cert_subject_data = (uint8_t *)mig_dst->cert_subject; + dst_info->cert_subject_data = reinterpret_cast(mig_dst->cert_subject); } else { dst_info->cert_subject_size = 0; dst_info->cert_subject_data = nullptr; @@ -733,10 +733,10 @@ static void main_channel_marshall_migrate_switch(SpiceMarshaller *m, MainChannel migrate.port = mig_target->port; migrate.sport = mig_target->sport; migrate.host_size = strlen(mig_target->host) + 1; - migrate.host_data = (uint8_t *)mig_target->host; + migrate.host_data = reinterpret_cast(mig_target->host); if (mig_target->cert_subject) { migrate.cert_subject_size = strlen(mig_target->cert_subject) + 1; - migrate.cert_subject_data = (uint8_t *)mig_target->cert_subject; + migrate.cert_subject_data = reinterpret_cast(mig_target->cert_subject); } else { migrate.cert_subject_size = 0; migrate.cert_subject_data = nullptr; diff --git a/server/main-channel.cpp b/server/main-channel.cpp index f6db2161..41716aba 100644 --- a/server/main-channel.cpp +++ b/server/main-channel.cpp @@ -82,7 +82,7 @@ bool MainChannelClient::handle_migrate_data(uint32_t size, void *message) { RedChannel *channel = get_channel(); MainChannelClient *mcc = this; - auto header = (SpiceMigrateDataHeader *)message; + auto header = static_cast(message); /* not supported with multi-clients */ spice_assert(channel->get_n_clients() == 1); @@ -98,8 +98,7 @@ bool MainChannelClient::handle_migrate_data(uint32_t size, void *message) return FALSE; } return reds_handle_migrate_data(channel->get_server(), mcc, - (SpiceMigrateDataMain *)(header + 1), - size); + reinterpret_cast(header + 1), size); } void MainChannel::push_multi_media_time(uint32_t time) @@ -143,7 +142,7 @@ bool MainChannelClient::handle_message(uint16_t type, uint32_t size, void *messa case SPICE_MSGC_MAIN_AGENT_START: { SpiceMsgcMainAgentStart *tokens; - tokens = (SpiceMsgcMainAgentStart *)message; + tokens = static_cast(message); reds_on_main_agent_start(reds, this, tokens->num_tokens); break; } @@ -153,7 +152,7 @@ bool MainChannelClient::handle_message(uint16_t type, uint32_t size, void *messa case SPICE_MSGC_MAIN_AGENT_TOKEN: { SpiceMsgcMainAgentTokens *tokens; - tokens = (SpiceMsgcMainAgentTokens *)message; + tokens = static_cast(message); reds_on_main_agent_tokens(reds, this, tokens->num_tokens); break; } @@ -170,7 +169,8 @@ bool MainChannelClient::handle_message(uint16_t type, uint32_t size, void *messa this->handle_migrate_connected(FALSE, FALSE); break; case SPICE_MSGC_MAIN_MIGRATE_DST_DO_SEAMLESS: - this->handle_migrate_dst_do_seamless(((SpiceMsgcMainMigrateDstDoSeamless *)message)->src_version); + this->handle_migrate_dst_do_seamless( + (static_cast(message))->src_version); break; case SPICE_MSGC_MAIN_MIGRATE_END: this->handle_migrate_end(); @@ -179,7 +179,7 @@ bool MainChannelClient::handle_message(uint16_t type, uint32_t size, void *messa reds_on_main_mouse_mode_request(reds, message, size); break; case SPICE_MSGC_PONG: - handle_pong((SpiceMsgPing *)message, size); + handle_pong(static_cast(message), size); break; default: return RedChannelClient::handle_message(type, size, message); @@ -264,7 +264,7 @@ int MainChannel::migrate_connect(RedsMigSpice *new_mig_target, int try_seamless) GList *clients = get_clients(); /* just test the first one */ - rcc = (RedChannelClient*) g_list_nth_data(clients, 0); + rcc = static_cast(g_list_nth_data(clients, 0)); if (!rcc->test_remote_cap(SPICE_MAIN_CAP_SEAMLESS_MIGRATE)) { return main_channel_connect_semi_seamless(this); diff --git a/server/main-dispatcher.cpp b/server/main-dispatcher.cpp index e448921e..9112c908 100644 --- a/server/main-dispatcher.cpp +++ b/server/main-dispatcher.cpp @@ -81,8 +81,8 @@ struct MainDispatcherClientDisconnectMessage { static void main_dispatcher_handle_channel_event(void *opaque, void *payload) { - auto reds = (RedsState*) opaque; - auto channel_event = (MainDispatcherChannelEventMessage*) payload; + auto reds = static_cast(opaque); + auto channel_event = static_cast(payload); reds_handle_channel_event(reds, channel_event->event, channel_event->info); } @@ -104,8 +104,8 @@ void MainDispatcher::channel_event(int event, SpiceChannelEventInfo *info) static void main_dispatcher_handle_migrate_complete(void *opaque, void *payload) { - auto reds = (RedsState*) opaque; - auto mig_complete = (MainDispatcherMigrateSeamlessDstCompleteMessage*) payload; + auto reds = static_cast(opaque); + auto mig_complete = static_cast(payload); reds_on_client_seamless_migrate_complete(reds, mig_complete->client); mig_complete->client->unref(); @@ -114,8 +114,8 @@ static void main_dispatcher_handle_migrate_complete(void *opaque, static void main_dispatcher_handle_mm_time_latency(void *opaque, void *payload) { - auto reds = (RedsState*) opaque; - auto msg = (MainDispatcherMmTimeLatencyMessage*) payload; + auto reds = static_cast(opaque); + auto msg = static_cast(payload); reds_set_client_mm_time_latency(reds, msg->client, msg->latency); msg->client->unref(); } @@ -123,8 +123,8 @@ static void main_dispatcher_handle_mm_time_latency(void *opaque, static void main_dispatcher_handle_client_disconnect(void *opaque, void *payload) { - auto reds = (RedsState*) opaque; - auto msg = (MainDispatcherClientDisconnectMessage*) payload; + auto reds = static_cast(opaque); + auto msg = static_cast(payload); spice_debug("client=%p", msg->client); reds_client_disconnect(reds, msg->client); diff --git a/server/memslot.c b/server/memslot.c index 91d0284b..4d9d02ba 100644 --- a/server/memslot.c +++ b/server/memslot.c @@ -128,7 +128,7 @@ void *memslot_get_virt(RedMemSlotInfo *info, QXLPHYSICAL addr, uint32_t add_size return NULL; } - return (void*)(uintptr_t)h_virt; + return (void *)h_virt; } void memslot_info_init(RedMemSlotInfo *info, diff --git a/server/red-channel-client.cpp b/server/red-channel-client.cpp index 30b50042..b7567ffb 100644 --- a/server/red-channel-client.cpp +++ b/server/red-channel-client.cpp @@ -765,27 +765,27 @@ static uint16_t mini_header_get_msg_type(SpiceDataHeaderOpaque *header) static void full_header_set_msg_type(SpiceDataHeaderOpaque *header, uint16_t type) { - ((SpiceDataHeader *)header->data)->type = GUINT16_TO_LE(type); + reinterpret_cast(header->data)->type = GUINT16_TO_LE(type); } static void mini_header_set_msg_type(SpiceDataHeaderOpaque *header, uint16_t type) { - ((SpiceMiniDataHeader *)header->data)->type = GUINT16_TO_LE(type); + reinterpret_cast(header->data)->type = GUINT16_TO_LE(type); } static void full_header_set_msg_size(SpiceDataHeaderOpaque *header, uint32_t size) { - ((SpiceDataHeader *)header->data)->size = GUINT32_TO_LE(size); + reinterpret_cast(header->data)->size = GUINT32_TO_LE(size); } static void mini_header_set_msg_size(SpiceDataHeaderOpaque *header, uint32_t size) { - ((SpiceMiniDataHeader *)header->data)->size = GUINT32_TO_LE(size); + reinterpret_cast(header->data)->size = GUINT32_TO_LE(size); } static void full_header_set_msg_serial(SpiceDataHeaderOpaque *header, uint64_t serial) { - ((SpiceDataHeader *)header->data)->serial = GUINT64_TO_LE(serial); + reinterpret_cast(header->data)->serial = GUINT64_TO_LE(serial); } static void mini_header_set_msg_serial(SpiceDataHeaderOpaque *header, uint64_t serial) @@ -795,7 +795,7 @@ static void mini_header_set_msg_serial(SpiceDataHeaderOpaque *header, uint64_t s static void full_header_set_msg_sub_list(SpiceDataHeaderOpaque *header, uint32_t sub_list) { - ((SpiceDataHeader *)header->data)->sub_list = GUINT32_TO_LE(sub_list); + (reinterpret_cast(header->data))->sub_list = GUINT32_TO_LE(sub_list); } static void mini_header_set_msg_sub_list(SpiceDataHeaderOpaque *header, uint32_t sub_list) @@ -1283,7 +1283,7 @@ bool RedChannelClient::handle_message(uint16_t type, uint32_t size, void *messag { switch (type) { case SPICE_MSGC_ACK_SYNC: - priv->ack_data.client_generation = ((SpiceMsgcAckSync *) message)->generation; + priv->ack_data.client_generation = static_cast(message)->generation; break; case SPICE_MSGC_ACK: if (priv->ack_data.client_generation == priv->ack_data.generation) { @@ -1306,7 +1306,7 @@ bool RedChannelClient::handle_message(uint16_t type, uint32_t size, void *messag handle_migrate_data_early(size, message); break; case SPICE_MSGC_PONG: - priv->handle_pong((SpiceMsgPing*) message); + priv->handle_pong(static_cast(message)); break; default: red_channel_warning(get_channel(), "invalid message type %u", diff --git a/server/red-channel.cpp b/server/red-channel.cpp index 9730c5a1..e3cc38a5 100644 --- a/server/red-channel.cpp +++ b/server/red-channel.cpp @@ -205,7 +205,7 @@ bool RedChannel::is_waiting_for_migrate_data() return FALSE; } spice_assert(n_clients == 1); - rcc = (RedChannelClient*) g_list_nth_data(priv->clients, 0); + rcc = static_cast(g_list_nth_data(priv->clients, 0)); return rcc->is_waiting_for_migrate_data(); } diff --git a/server/red-parse-qxl.cpp b/server/red-parse-qxl.cpp index 9cccff31..68b9759d 100644 --- a/server/red-parse-qxl.cpp +++ b/server/red-parse-qxl.cpp @@ -116,7 +116,7 @@ static uint8_t *red_linearize_chunk(RedDataChunk *head, size_t size, bool *free_ return head->data; } - ptr = data = (uint8_t*) g_malloc(size); + ptr = data = static_cast(g_malloc(size)); *free_chunk = true; for (chunk = head; chunk != nullptr && size > 0; chunk = chunk->next_chunk) { copy = MIN(chunk->data_size, size); @@ -157,7 +157,8 @@ static size_t red_get_data_chunks_ptr(RedMemSlotInfo *slots, int group_id, } memslot_id = memslot_get_id(slots, next_chunk); - qxl = (QXLDataChunk *)memslot_get_virt(slots, next_chunk, sizeof(*qxl), group_id); + qxl = static_cast( + memslot_get_virt(slots, next_chunk, sizeof(*qxl), group_id)); if (qxl == nullptr) { goto error; } @@ -210,7 +211,7 @@ static size_t red_get_data_chunks(RedMemSlotInfo *slots, int group_id, QXLDataChunk *qxl; int memslot_id = memslot_get_id(slots, addr); - qxl = (QXLDataChunk *)memslot_get_virt(slots, addr, sizeof(*qxl), group_id); + qxl = static_cast(memslot_get_virt(slots, addr, sizeof(*qxl), group_id)); if (qxl == nullptr) { return INVALID_SIZE; } @@ -265,7 +266,7 @@ static SpicePath *red_get_path(RedMemSlotInfo *slots, int group_id, int i; uint32_t count; - qxl = (QXLPath *)memslot_get_virt(slots, addr, sizeof(*qxl), group_id); + qxl = static_cast(memslot_get_virt(slots, addr, sizeof(*qxl), group_id)); if (qxl == nullptr) { return nullptr; } @@ -281,25 +282,25 @@ static SpicePath *red_get_path(RedMemSlotInfo *slots, int group_id, n_segments = 0; mem_size = sizeof(*red); - start = (QXLPathSeg*)data; - end = (QXLPathSeg*)(data + size); + start = reinterpret_cast(data); + end = reinterpret_cast(data + size); while (start+1 < end) { n_segments++; count = start->count; - segment_size = sizeof(SpicePathSeg) + (uint64_t) count * sizeof(SpicePointFix); + segment_size = sizeof(SpicePathSeg) + uint64_t{count} * sizeof(SpicePointFix); mem_size += sizeof(SpicePathSeg *) + SPICE_ALIGN(segment_size, 4); /* avoid going backward with 32 bit architectures */ spice_assert((uint64_t) count * sizeof(QXLPointFix) <= (char*) end - (char*) &start->points[0]); - start = (QXLPathSeg*)(&start->points[count]); + start = reinterpret_cast(&start->points[count]); } - red = (SpicePath*) g_malloc(mem_size); + red = static_cast(g_malloc(mem_size)); red->num_segments = n_segments; - start = (QXLPathSeg*)data; - end = (QXLPathSeg*)(data + size); - seg = (SpicePathSeg*)&red->segments[n_segments]; + start = reinterpret_cast(data); + end = reinterpret_cast(data + size); + seg = reinterpret_cast(&red->segments[n_segments]); n_segments = 0; mem_size2 = sizeof(*red); while (start+1 < end && n_segments < red->num_segments) { @@ -309,7 +310,7 @@ static SpicePath *red_get_path(RedMemSlotInfo *slots, int group_id, /* Protect against overflow in size calculations before writing to memory */ /* Verify that we didn't overflow due to guest changing data */ - mem_size2 += sizeof(SpicePathSeg) + (uint64_t) count * sizeof(SpicePointFix); + mem_size2 += sizeof(SpicePathSeg) + uint64_t{count} * sizeof(SpicePointFix); spice_assert(mem_size2 <= mem_size); seg->flags = start->flags; @@ -318,8 +319,8 @@ static SpicePath *red_get_path(RedMemSlotInfo *slots, int group_id, seg->points[i].x = start->points[i].x; seg->points[i].y = start->points[i].y; } - start = (QXLPathSeg*)(&start->points[i]); - seg = (SpicePathSeg*)(&seg->points[i]); + start = reinterpret_cast(&start->points[i]); + seg = reinterpret_cast(&seg->points[i]); } /* Ensure guest didn't tamper with segment count */ spice_assert(n_segments == red->num_segments); @@ -343,7 +344,7 @@ static SpiceClipRects *red_get_clip_rects(RedMemSlotInfo *slots, int group_id, int i; uint32_t num_rects; - qxl = (QXLClipRects *)memslot_get_virt(slots, addr, sizeof(*qxl), group_id); + qxl = static_cast(memslot_get_virt(slots, addr, sizeof(*qxl), group_id)); if (qxl == nullptr) { return nullptr; } @@ -363,10 +364,10 @@ static SpiceClipRects *red_get_clip_rects(RedMemSlotInfo *slots, int group_id, */ spice_assert((uint64_t) num_rects * sizeof(QXLRect) == size); SPICE_VERIFY(sizeof(SpiceRect) == sizeof(QXLRect)); - red = (SpiceClipRects*) g_malloc(sizeof(*red) + num_rects * sizeof(SpiceRect)); + red = static_cast(g_malloc(sizeof(*red) + num_rects * sizeof(SpiceRect))); red->num_rects = num_rects; - start = (QXLRect*)data; + start = reinterpret_cast(data); for (i = 0; i < red->num_rects; i++) { red_get_rect_ptr(red->rects + i, start++); } @@ -390,7 +391,7 @@ static SpiceChunks *red_get_image_data_flat(RedMemSlotInfo *slots, int group_id, data = spice_chunks_new(1); data->data_size = size; - data->chunk[0].data = (uint8_t*) bitmap_virt; + data->chunk[0].data = static_cast(bitmap_virt); data->chunk[0].len = size; return data; } @@ -451,7 +452,7 @@ static bool bitmap_consistent(SpiceBitmap *bitmap) bpp = MAP_BITMAP_FMT_TO_BITS_PER_PIXEL[bitmap->format]; - if (bitmap->stride < (((uint64_t) bitmap->x * bpp + 7U) / 8U)) { + if (bitmap->stride < ((uint64_t{bitmap->x} * bpp + 7U) / 8U)) { spice_warning("image stride too small for width: %d < ((%d * %d + 7) / 8) (%s=%d)", bitmap->stride, bitmap->x, bpp, bitmap_format_to_string(bitmap->format), @@ -476,7 +477,7 @@ static SpiceImage *red_get_image(RedMemSlotInfo *slots, int group_id, return nullptr; } - qxl = (QXLImage *)memslot_get_virt(slots, addr, sizeof(*qxl), group_id); + qxl = static_cast(memslot_get_virt(slots, addr, sizeof(*qxl), group_id)); if (qxl == nullptr) { return nullptr; } @@ -519,8 +520,7 @@ static SpiceImage *red_get_image(RedMemSlotInfo *slots, int group_id, if (palette) { QXLPalette *qp; int i, num_ents; - qp = (QXLPalette *)memslot_get_virt(slots, palette, - sizeof(*qp), group_id); + qp = static_cast(memslot_get_virt(slots, palette, sizeof(*qp), group_id)); if (qp == nullptr) { goto error; } @@ -530,7 +530,8 @@ static SpiceImage *red_get_image(RedMemSlotInfo *slots, int group_id, num_ents * sizeof(qp->ents[0]), group_id)) { goto error; } - rp = (SpicePalette*) g_malloc(num_ents * sizeof(rp->ents[0]) + sizeof(*rp)); + rp = + static_cast(g_malloc(num_ents * sizeof(rp->ents[0]) + sizeof(*rp))); rp->unique = qp->unique; rp->num_ents = num_ents; if (flags & QXL_COMMAND_FLAG_COMPAT_16BPP) { @@ -545,7 +546,7 @@ static SpiceImage *red_get_image(RedMemSlotInfo *slots, int group_id, red->u.bitmap.palette = rp; red->u.bitmap.palette_id = rp->unique; } - bitmap_size = (uint64_t) red->u.bitmap.y * red->u.bitmap.stride; + bitmap_size = uint64_t{red->u.bitmap.y} * red->u.bitmap.stride; if (bitmap_size > MAX_DATA_CHUNK) { goto error; } @@ -576,9 +577,8 @@ static SpiceImage *red_get_image(RedMemSlotInfo *slots, int group_id, break; case SPICE_IMAGE_TYPE_QUIC: red->u.quic.data_size = qxl->quic.data_size; - size = red_get_data_chunks_ptr(slots, group_id, - memslot_get_id(slots, addr), - &chunks, (QXLDataChunk *)qxl->quic.data); + size = red_get_data_chunks_ptr(slots, group_id, memslot_get_id(slots, addr), &chunks, + reinterpret_cast(qxl->quic.data)); if (size == INVALID_SIZE || size != red->u.quic.data_size) { red_put_data_chunks(&chunks); goto error; @@ -788,7 +788,8 @@ static bool get_transform(RedMemSlotInfo *slots, if (qxl_transform == 0) return false; - t = (uint32_t *)memslot_get_virt(slots, qxl_transform, sizeof(*dst_transform), group_id); + t = static_cast( + memslot_get_virt(slots, qxl_transform, sizeof(*dst_transform), group_id)); if (t == nullptr) return false; @@ -858,11 +859,12 @@ static bool red_get_stroke_ptr(RedMemSlotInfo *slots, int group_id, uint8_t *buf; style_nseg = qxl->attr.style_nseg; - red->attr.style = (SPICE_FIXED28_4*) g_malloc_n(style_nseg, sizeof(SPICE_FIXED28_4)); + red->attr.style = + static_cast(g_malloc_n(style_nseg, sizeof(SPICE_FIXED28_4))); red->attr.style_nseg = style_nseg; spice_assert(qxl->attr.style); - buf = (uint8_t *)memslot_get_virt(slots, qxl->attr.style, - style_nseg * sizeof(QXLFIXED), group_id); + buf = static_cast( + memslot_get_virt(slots, qxl->attr.style, style_nseg * sizeof(QXLFIXED), group_id)); if (buf == nullptr) { return false; } @@ -902,7 +904,7 @@ static SpiceString *red_get_string(RedMemSlotInfo *slots, int group_id, unsigned int bpp = 0; uint16_t qxl_flags, qxl_length; - qxl = (QXLString *)memslot_get_virt(slots, addr, sizeof(*qxl), group_id); + qxl = static_cast(memslot_get_virt(slots, addr, sizeof(*qxl), group_id)); if (qxl == nullptr) { return nullptr; } @@ -929,8 +931,8 @@ static SpiceString *red_get_string(RedMemSlotInfo *slots, int group_id, } spice_assert(bpp != 0); - start = (QXLRasterGlyph*)data; - end = (QXLRasterGlyph*)(data + chunk_size); + start = reinterpret_cast(data); + end = reinterpret_cast(data + chunk_size); red_size = sizeof(SpiceString); glyphs = 0; while (start < end) { @@ -943,18 +945,18 @@ static SpiceString *red_get_string(RedMemSlotInfo *slots, int group_id, * buffer overflow as this on 32 bit can cause overflow * on the pointer arithmetic */ spice_assert(glyph_size <= (char*) end - (char*) &start->data[0]); - start = (QXLRasterGlyph*)(&start->data[glyph_size]); + start = reinterpret_cast(&start->data[glyph_size]); } spice_assert(start <= end); spice_assert(glyphs == qxl_length); - red = (SpiceString*) g_malloc(red_size); + red = static_cast(g_malloc(red_size)); red->length = qxl_length; red->flags = qxl_flags; - start = (QXLRasterGlyph*)data; - end = (QXLRasterGlyph*)(data + chunk_size); - glyph = (SpiceRasterGlyph *)&red->glyphs[red->length]; + start = reinterpret_cast(data); + end = reinterpret_cast(data + chunk_size); + glyph = reinterpret_cast(&red->glyphs[red->length]); for (i = 0; i < red->length; i++) { spice_assert((QXLRasterGlyph*)(&start->data[0]) <= end); red->glyphs[i] = glyph; @@ -966,7 +968,7 @@ static SpiceString *red_get_string(RedMemSlotInfo *slots, int group_id, /* see above for similar test */ spice_assert(glyph_size <= (char*) end - (char*) &start->data[0]); memcpy(glyph->data, start->data, glyph_size); - start = (QXLRasterGlyph*)(&start->data[glyph_size]); + start = reinterpret_cast(&start->data[glyph_size]); glyph = SPICE_ALIGNED_CAST(SpiceRasterGlyph*, (((uint8_t *)glyph) + SPICE_ALIGN(sizeof(SpiceRasterGlyph) + glyph_size, 4))); @@ -1038,7 +1040,7 @@ static bool red_get_native_drawable(QXLInstance *qxl_instance, RedMemSlotInfo *s QXLDrawable *qxl; int i; - qxl = (QXLDrawable *)memslot_get_virt(slots, addr, sizeof(*qxl), group_id); + qxl = static_cast(memslot_get_virt(slots, addr, sizeof(*qxl), group_id)); if (qxl == nullptr) { return false; } @@ -1116,7 +1118,7 @@ static bool red_get_compat_drawable(QXLInstance *qxl_instance, RedMemSlotInfo *s { QXLCompatDrawable *qxl; - qxl = (QXLCompatDrawable *)memslot_get_virt(slots, addr, sizeof(*qxl), group_id); + qxl = static_cast(memslot_get_virt(slots, addr, sizeof(*qxl), group_id)); if (qxl == nullptr) { return false; } @@ -1272,7 +1274,7 @@ static bool red_get_update_cmd(QXLInstance *qxl_instance, RedMemSlotInfo *slots, { QXLUpdateCmd *qxl; - qxl = (QXLUpdateCmd *)memslot_get_virt(slots, addr, sizeof(*qxl), group_id); + qxl = static_cast(memslot_get_virt(slots, addr, sizeof(*qxl), group_id)); if (qxl == nullptr) { return false; } @@ -1313,7 +1315,7 @@ static bool red_get_message(QXLInstance *qxl_instance, RedMemSlotInfo *slots, in * luckily this is for debug logging only, * so we can just ignore it by default. */ - qxl = (QXLMessage *)memslot_get_virt(slots, addr, sizeof(*qxl), group_id); + qxl = static_cast(memslot_get_virt(slots, addr, sizeof(*qxl), group_id)); if (qxl == nullptr) { return false; } @@ -1322,7 +1324,7 @@ static bool red_get_message(QXLInstance *qxl_instance, RedMemSlotInfo *slots, in memslot_id = memslot_get_id(slots, addr+sizeof(*qxl)); len = memslot_max_size_virt(slots, ((intptr_t) qxl)+sizeof(*qxl), memslot_id, group_id); len = MIN(len, 100000); - end = (uint8_t *)memchr(qxl->data, 0, len); + end = static_cast(memchr(qxl->data, 0, len)); if (end == nullptr) { return false; } @@ -1376,14 +1378,14 @@ bool red_validate_surface(uint32_t width, uint32_t height, } /* check stride is larger than required bytes */ - size = ((uint64_t) width * bpp + 7U) / 8U; + size = (uint64_t{width} * bpp + 7U) / 8U; /* the uint32_t conversion is here to avoid problems with -2^31 value */ - if (stride == G_MININT32 || size > (uint32_t) abs(stride)) { + if (stride == G_MININT32 || size > uint32_t{abs(stride)}) { return false; } /* the multiplication can overflow, also abs(-2^31) may return a negative value */ - size = (uint64_t) height * abs(stride); + size = uint64_t{height} * abs(stride); return size <= MAX_DATA_CHUNK; } @@ -1394,7 +1396,7 @@ static bool red_get_surface_cmd(QXLInstance *qxl_instance, RedMemSlotInfo *slots QXLSurfaceCmd *qxl; uint64_t size; - qxl = (QXLSurfaceCmd *)memslot_get_virt(slots, addr, sizeof(*qxl), group_id); + qxl = static_cast(memslot_get_virt(slots, addr, sizeof(*qxl), group_id)); if (qxl == nullptr) { return false; } @@ -1417,8 +1419,8 @@ static bool red_get_surface_cmd(QXLInstance *qxl_instance, RedMemSlotInfo *slots } size = red->u.surface_create.height * abs(red->u.surface_create.stride); - red->u.surface_create.data = - (uint8_t*)memslot_get_virt(slots, qxl->u.surface_create.data, size, group_id); + red->u.surface_create.data = static_cast( + memslot_get_virt(slots, qxl->u.surface_create.data, size, group_id)); if (red->u.surface_create.data == nullptr) { return false; } @@ -1451,7 +1453,7 @@ static bool red_get_cursor(RedMemSlotInfo *slots, int group_id, uint8_t *data; bool free_data; - qxl = (QXLCursor *)memslot_get_virt(slots, addr, sizeof(*qxl), group_id); + qxl = static_cast(memslot_get_virt(slots, addr, sizeof(*qxl), group_id)); if (qxl == nullptr) { return false; } @@ -1477,7 +1479,7 @@ static bool red_get_cursor(RedMemSlotInfo *slots, int group_id, if (free_data) { red->data = data; } else { - red->data = (uint8_t*) g_memdup2(data, size); + red->data = static_cast(g_memdup2(data, size)); } // Arrived here we could note that we are not going to use anymore cursor data // and we could be tempted to release resource back to QXL. Don't do that! @@ -1497,7 +1499,7 @@ static bool red_get_cursor_cmd(QXLInstance *qxl_instance, RedMemSlotInfo *slots, { QXLCursorCmd *qxl; - qxl = (QXLCursorCmd *)memslot_get_virt(slots, addr, sizeof(*qxl), group_id); + qxl = static_cast(memslot_get_virt(slots, addr, sizeof(*qxl), group_id)); if (qxl == nullptr) { return false; } diff --git a/server/red-pipe-item.cpp b/server/red-pipe-item.cpp index a81de073..12b991ff 100644 --- a/server/red-pipe-item.cpp +++ b/server/red-pipe-item.cpp @@ -27,7 +27,7 @@ RedPipeItem::RedPipeItem(int init_type): static void marshaller_unref_pipe_item(uint8_t *, void *opaque) { - auto item = (RedPipeItem*) opaque; + auto item = static_cast(opaque); shared_ptr_unref(item); } diff --git a/server/red-qxl.cpp b/server/red-qxl.cpp index 37b9e540..48c293ae 100644 --- a/server/red-qxl.cpp +++ b/server/red-qxl.cpp @@ -550,7 +550,8 @@ uint32_t red_qxl_marshall_device_display_info(const QXLInstance *qxl, SpiceMarsh spice_marshaller_add_uint32(m, i); spice_marshaller_add_uint32(m, qxl_state->device_display_ids[i]); spice_marshaller_add_uint32(m, device_address_len); - spice_marshaller_add(m, (const uint8_t*) (void*) device_address, device_address_len); + spice_marshaller_add(m, reinterpret_cast(device_address), + device_address_len); ++device_count; g_debug(" (qxl) channel_id: %u monitor_id: %zu, device_address: %s, " @@ -680,7 +681,7 @@ void red_qxl_attach_worker(QXLInstance *qxl) * Passing QXLInstance pointer instead allows these programs to keep working * although spice_replay_next_cmd declaration changed */ if (qxl_interface->attache_worker) { - qxl_interface->attache_worker(qxl, (QXLWorker *) qxl); + qxl_interface->attache_worker(qxl, reinterpret_cast(qxl)); } } diff --git a/server/red-replay-qxl.cpp b/server/red-replay-qxl.cpp index bdb25a15..3b59be6c 100644 --- a/server/red-replay-qxl.cpp +++ b/server/red-replay-qxl.cpp @@ -29,8 +29,16 @@ #include "memslot.h" #include "red-parse-qxl.h" -#define QXLPHYSICAL_FROM_PTR(ptr) ((QXLPHYSICAL)(uintptr_t)(ptr)) -#define QXLPHYSICAL_TO_PTR(phy) ((void*)(uintptr_t)(phy)) +static inline QXLPHYSICAL QXLPHYSICAL_FROM_PTR(const void *ptr) +{ + return static_cast(reinterpret_cast(ptr)); +} + +template +static inline T* QXLPHYSICAL_TO_PTR(QXLPHYSICAL phy) +{ + return reinterpret_cast(static_cast(phy)); +} enum replay_t { REPLAY_OK = 0, @@ -236,7 +244,7 @@ static replay_t read_binary(SpiceReplay *replay, const char *prefix, size_t *siz } if (*buf == nullptr) { - *buf = (uint8_t*) replay_malloc(replay, *size + base_size); + *buf = static_cast(replay_malloc(replay, *size + base_size)); } #if 0 { @@ -252,7 +260,7 @@ static replay_t read_binary(SpiceReplay *replay, const char *prefix, size_t *siz if (replay->error) { return REPLAY_ERROR; } - zlib_buffer = (uint8_t*) replay_malloc(replay, zlib_size); + zlib_buffer = static_cast(replay_malloc(replay, zlib_size)); if (replay_fread(replay, zlib_buffer, zlib_size) != zlib_size) { return REPLAY_ERROR; } @@ -310,7 +318,7 @@ static ssize_t red_replay_data_chunks(SpiceReplay *replay, const char *prefix, if (read_binary(replay, prefix, &next_data_size, mem, base_size) == REPLAY_ERROR) { return -1; } - cur = (QXLDataChunk*)(*mem + base_size - sizeof(QXLDataChunk)); + cur = reinterpret_cast(*mem + base_size - sizeof(QXLDataChunk)); cur->data_size = next_data_size; data_size = cur->data_size; cur->next_chunk = cur->prev_chunk = 0; @@ -322,7 +330,7 @@ static ssize_t red_replay_data_chunks(SpiceReplay *replay, const char *prefix, } cur->next_chunk = QXLPHYSICAL_FROM_PTR(data); data_size += next_data_size; - next = (QXLDataChunk*) QXLPHYSICAL_TO_PTR(cur->next_chunk); + next = QXLPHYSICAL_TO_PTR(cur->next_chunk); next->prev_chunk = QXLPHYSICAL_FROM_PTR(cur); next->data_size = next_data_size; next->next_chunk = 0; @@ -334,12 +342,12 @@ static ssize_t red_replay_data_chunks(SpiceReplay *replay, const char *prefix, static void red_replay_data_chunks_free(SpiceReplay *replay, void *data, size_t base_size) { - auto cur = (QXLDataChunk *)((uint8_t*)data + - (base_size ? base_size - sizeof(QXLDataChunk) : 0)); + auto cur = reinterpret_cast(static_cast(data) + + (base_size ? base_size - sizeof(QXLDataChunk) : 0)); - cur = (QXLDataChunk*) QXLPHYSICAL_TO_PTR(cur->next_chunk); + cur = QXLPHYSICAL_TO_PTR(cur->next_chunk); while (cur) { - auto next = (QXLDataChunk*) QXLPHYSICAL_TO_PTR(cur->next_chunk); + auto next = QXLPHYSICAL_TO_PTR(cur->next_chunk); g_free(cur); cur = next; } @@ -374,7 +382,8 @@ static QXLPath *red_replay_path(SpiceReplay *replay) QXLPath *qxl = nullptr; ssize_t data_size; - data_size = red_replay_data_chunks(replay, "path", (uint8_t**)&qxl, sizeof(QXLPath)); + data_size = + red_replay_data_chunks(replay, "path", reinterpret_cast(&qxl), sizeof(QXLPath)); if (data_size < 0) { return nullptr; } @@ -384,7 +393,7 @@ static QXLPath *red_replay_path(SpiceReplay *replay) static void red_replay_path_free(SpiceReplay *replay, QXLPHYSICAL p) { - auto qxl = (QXLPath*) QXLPHYSICAL_TO_PTR(p); + auto qxl = QXLPHYSICAL_TO_PTR(p); red_replay_data_chunks_free(replay, qxl, sizeof(*qxl)); } @@ -398,7 +407,8 @@ static QXLClipRects *red_replay_clip_rects(SpiceReplay *replay) if (replay->error) { return nullptr; } - if (red_replay_data_chunks(replay, "clip_rects", (uint8_t**)&qxl, sizeof(QXLClipRects)) < 0) { + if (red_replay_data_chunks(replay, "clip_rects", reinterpret_cast(&qxl), + sizeof(QXLClipRects)) < 0) { return nullptr; } qxl->num_rects = num_rects; @@ -436,7 +446,7 @@ static QXLImage *red_replay_image(SpiceReplay *replay, uint32_t flags) return nullptr; } - qxl = (QXLImage*)replay_malloc0(replay, sizeof(QXLImage)); + qxl = static_cast(replay_malloc0(replay, sizeof(QXLImage))); replay_fscanf(replay, "descriptor.id %" SCNu64 "\n", &qxl->descriptor.id); replay_fscanf(replay, "descriptor.type %d\n", &temp); qxl->descriptor.type = temp; replay_fscanf(replay, "descriptor.flags %d\n", &temp); qxl->descriptor.flags = temp; @@ -463,7 +473,8 @@ static QXLImage *red_replay_image(SpiceReplay *replay, uint32_t flags) if (replay->error) { return nullptr; } - qp = (QXLPalette*) replay_malloc(replay, sizeof(QXLPalette) + num_ents * sizeof(qp->ents[0])); + qp = static_cast( + replay_malloc(replay, sizeof(QXLPalette) + num_ents * sizeof(qp->ents[0]))); qp->num_ents = num_ents; qxl->bitmap.palette = QXLPHYSICAL_FROM_PTR(qp); replay_fscanf(replay, "unique %" SCNu64 "\n", &qp->unique); @@ -502,7 +513,7 @@ static QXLImage *red_replay_image(SpiceReplay *replay, uint32_t flags) return nullptr; } data = nullptr; - size = red_replay_data_chunks(replay, "quic.data", (uint8_t**)&data, + size = red_replay_data_chunks(replay, "quic.data", reinterpret_cast(&data), sizeof(QXLImageDescriptor) + sizeof(QXLQUICData) + sizeof(QXLDataChunk)); spice_assert(size == qxl->quic.data_size); @@ -519,17 +530,18 @@ static QXLImage *red_replay_image(SpiceReplay *replay, uint32_t flags) static void red_replay_image_free(SpiceReplay *replay, QXLPHYSICAL p, uint32_t flags) { - auto qxl = (QXLImage*) QXLPHYSICAL_TO_PTR(p); + auto qxl = QXLPHYSICAL_TO_PTR(p); if (!qxl) return; switch (qxl->descriptor.type) { case SPICE_IMAGE_TYPE_BITMAP: - g_free(QXLPHYSICAL_TO_PTR(qxl->bitmap.palette)); + g_free(QXLPHYSICAL_TO_PTR(qxl->bitmap.palette)); if (qxl->bitmap.flags & QXL_BITMAP_DIRECT) { - g_free(QXLPHYSICAL_TO_PTR(qxl->bitmap.data)); + g_free(QXLPHYSICAL_TO_PTR(qxl->bitmap.data)); } else { - red_replay_data_chunks_free(replay, QXLPHYSICAL_TO_PTR(qxl->bitmap.data), 0); + red_replay_data_chunks_free(replay, + QXLPHYSICAL_TO_PTR(qxl->bitmap.data), 0); } break; case SPICE_IMAGE_TYPE_SURFACE: @@ -738,7 +750,7 @@ static void red_replay_stroke_free(SpiceReplay *replay, QXLStroke *qxl, uint32_t { red_replay_path_free(replay, qxl->path); if (qxl->attr.flags & SPICE_LINE_FLAGS_STYLED) { - g_free(QXLPHYSICAL_TO_PTR(qxl->attr.style)); + g_free(QXLPHYSICAL_TO_PTR(qxl->attr.style)); } red_replay_brush_free(replay, &qxl->brush, flags); } @@ -755,7 +767,8 @@ static QXLString *red_replay_string(SpiceReplay *replay) replay_fscanf(replay, "data_size %d\n", &data_size); replay_fscanf(replay, "length %d\n", &temp); length = temp; replay_fscanf(replay, "flags %d\n", &temp); flags = temp; - chunk_size = red_replay_data_chunks(replay, "string", (uint8_t**)&qxl, sizeof(QXLString)); + chunk_size = red_replay_data_chunks(replay, "string", reinterpret_cast(&qxl), + sizeof(QXLString)); if (chunk_size < 0) { return nullptr; } @@ -785,7 +798,7 @@ static void red_replay_text_ptr(SpiceReplay *replay, QXLText *qxl, uint32_t flag static void red_replay_text_free(SpiceReplay *replay, QXLText *qxl, uint32_t flags) { - red_replay_string_free(replay, (QXLString*) QXLPHYSICAL_TO_PTR(qxl->str)); + red_replay_string_free(replay, QXLPHYSICAL_TO_PTR(qxl->str)); red_replay_brush_free(replay, &qxl->fore_brush, flags); red_replay_brush_free(replay, &qxl->back_brush, flags); } @@ -837,7 +850,8 @@ static void red_replay_clip_free(SpiceReplay *replay, QXLClip *qxl) { switch (qxl->type) { case SPICE_CLIP_TYPE_RECTS: - red_replay_clip_rects_free(replay, (QXLClipRects*) QXLPHYSICAL_TO_PTR(qxl->data)); + red_replay_clip_rects_free(replay, + QXLPHYSICAL_TO_PTR(qxl->data)); break; } } @@ -876,15 +890,16 @@ static void red_replay_composite_ptr(SpiceReplay *replay, QXLComposite *qxl, uin static void red_replay_composite_free(SpiceReplay *replay, QXLComposite *qxl, uint32_t flags) { red_replay_image_free(replay, qxl->src, flags); - g_free(QXLPHYSICAL_TO_PTR(qxl->src_transform)); + g_free(QXLPHYSICAL_TO_PTR(qxl->src_transform)); red_replay_image_free(replay, qxl->mask, flags); - g_free(QXLPHYSICAL_TO_PTR(qxl->mask_transform)); + g_free(QXLPHYSICAL_TO_PTR(qxl->mask_transform)); } static QXLDrawable *red_replay_native_drawable(SpiceReplay *replay, uint32_t flags) { - auto qxl = (QXLDrawable*) replay_malloc0(replay, sizeof(QXLDrawable)); // TODO - this is too large usually + auto qxl = static_cast( + replay_malloc0(replay, sizeof(QXLDrawable))); // TODO - this is too large usually int i; int temp; @@ -1024,7 +1039,8 @@ static void red_replay_native_drawable_free(SpiceReplay *replay, QXLDrawable *qx static QXLCompatDrawable *red_replay_compat_drawable(SpiceReplay *replay, uint32_t flags) { int temp; - auto qxl = (QXLCompatDrawable*) replay_malloc0(replay, sizeof(QXLCompatDrawable)); // TODO - too large usually + auto qxl = static_cast( + replay_malloc0(replay, sizeof(QXLCompatDrawable))); // TODO - too large usually red_replay_rect_ptr(replay, "bbox", &qxl->bbox); red_replay_clip_ptr(replay, &qxl->clip); @@ -1101,7 +1117,7 @@ static QXLPHYSICAL red_replay_drawable(SpiceReplay *replay, uint32_t flags) static QXLUpdateCmd *red_replay_update_cmd(SpiceReplay *replay) { - auto qxl = (QXLUpdateCmd*) replay_malloc0(replay, sizeof(QXLUpdateCmd)); + auto qxl = static_cast(replay_malloc0(replay, sizeof(QXLUpdateCmd))); replay_fscanf(replay, "update\n"); red_replay_rect_ptr(replay, "area", &qxl->area); @@ -1120,7 +1136,7 @@ static QXLMessage *red_replay_message(SpiceReplay *replay) QXLMessage *qxl = nullptr; size_t size; - read_binary(replay, "message", &size, (uint8_t**)&qxl, sizeof(QXLMessage)); + read_binary(replay, "message", &size, reinterpret_cast(&qxl), sizeof(QXLMessage)); return qxl; } @@ -1129,7 +1145,7 @@ static QXLSurfaceCmd *red_replay_surface_cmd(SpiceReplay *replay) size_t size; size_t read_size; int temp; - auto qxl = (QXLSurfaceCmd*) replay_malloc0(replay, sizeof(QXLSurfaceCmd)); + auto qxl = static_cast(replay_malloc0(replay, sizeof(QXLSurfaceCmd))); replay_fscanf(replay, "surface_cmd\n"); replay_fscanf(replay, "surface_id %d\n", &qxl->surface_id); @@ -1174,7 +1190,7 @@ static void red_replay_surface_cmd_free(SpiceReplay *replay, QXLSurfaceCmd *qxl) replay_id_free(replay, qxl->surface_id); } - g_free(QXLPHYSICAL_TO_PTR(qxl->u.surface_create.data)); + g_free(QXLPHYSICAL_TO_PTR(qxl->u.surface_create.data)); g_free(qxl); } @@ -1200,7 +1216,8 @@ static QXLCursor *red_replay_cursor(SpiceReplay *replay) if (replay->error) { return nullptr; } - data_size = red_replay_data_chunks(replay, "cursor", (uint8_t**)&qxl, sizeof(QXLCursor)); + data_size = red_replay_data_chunks(replay, "cursor", reinterpret_cast(&qxl), + sizeof(QXLCursor)); if (data_size < 0) { return nullptr; } @@ -1212,7 +1229,7 @@ static QXLCursor *red_replay_cursor(SpiceReplay *replay) static QXLCursorCmd *red_replay_cursor_cmd(SpiceReplay *replay) { int temp; - auto qxl = (QXLCursorCmd*) replay_malloc0(replay, sizeof(QXLCursorCmd)); + auto qxl = static_cast(replay_malloc0(replay, sizeof(QXLCursorCmd))); replay_fscanf(replay, "cursor_cmd\n"); replay_fscanf(replay, "type %d\n", &temp); @@ -1243,7 +1260,7 @@ static QXLCursorCmd *red_replay_cursor_cmd(SpiceReplay *replay) static void red_replay_cursor_cmd_free(SpiceReplay *replay, QXLCursorCmd *qxl) { if (qxl->type == QXL_CURSOR_SET) { - auto cursor = (QXLCursor*) QXLPHYSICAL_TO_PTR(qxl->u.set.shape); + auto cursor = QXLPHYSICAL_TO_PTR(qxl->u.set.shape); red_replay_data_chunks_free(replay, cursor, sizeof(*cursor)); } @@ -1332,7 +1349,7 @@ SPICE_GNUC_VISIBLE QXLCommandExt* spice_replay_next_cmd(SpiceReplay *replay, replay_handle_dev_input(instance, replay, type); } } - cmd = (QXLCommandExt*) replay_malloc0(replay, sizeof(QXLCommandExt)); + cmd = static_cast(replay_malloc0(replay, sizeof(QXLCommandExt))); cmd->cmd.type = type; cmd->group_id = 0; spice_debug("command %" G_GUINT64_FORMAT ", %d", timestamp, cmd->cmd.type); @@ -1365,7 +1382,7 @@ SPICE_GNUC_VISIBLE QXLCommandExt* spice_replay_next_cmd(SpiceReplay *replay, case QXL_CMD_UPDATE: case QXL_CMD_SURFACE: case QXL_CMD_CURSOR: - info = (QXLReleaseInfo*) QXLPHYSICAL_TO_PTR(cmd->cmd.data); + info = QXLPHYSICAL_TO_PTR(cmd->cmd.data); info->id = (uintptr_t)cmd; } @@ -1399,22 +1416,22 @@ SPICE_GNUC_VISIBLE void spice_replay_free_cmd(SpiceReplay *replay, QXLCommandExt case QXL_CMD_DRAW: { // FIXME: compat flag must be saved somewhere... spice_return_if_fail(cmd->flags == 0); - auto qxl = (QXLDrawable*) QXLPHYSICAL_TO_PTR(cmd->cmd.data); + auto qxl = QXLPHYSICAL_TO_PTR(cmd->cmd.data); red_replay_native_drawable_free(replay, qxl, cmd->flags); break; } case QXL_CMD_UPDATE: { - auto qxl = (QXLUpdateCmd*) QXLPHYSICAL_TO_PTR(cmd->cmd.data); + auto qxl = QXLPHYSICAL_TO_PTR(cmd->cmd.data); g_free(qxl); break; } case QXL_CMD_SURFACE: { - auto qxl = (QXLSurfaceCmd*) QXLPHYSICAL_TO_PTR(cmd->cmd.data); + auto qxl = QXLPHYSICAL_TO_PTR(cmd->cmd.data); red_replay_surface_cmd_free(replay, qxl); break; } case QXL_CMD_CURSOR: { - auto qxl = (QXLCursorCmd*) QXLPHYSICAL_TO_PTR(cmd->cmd.data); + auto qxl = QXLPHYSICAL_TO_PTR(cmd->cmd.data); red_replay_cursor_cmd_free(replay, qxl); break; } diff --git a/server/red-stream-device.cpp b/server/red-stream-device.cpp index 92ba0d94..6f2b64c9 100644 --- a/server/red-stream-device.cpp +++ b/server/red-stream-device.cpp @@ -81,7 +81,7 @@ StreamDevice::partial_read() /* read header */ while (hdr_pos < sizeof(hdr)) { - n = read((uint8_t *) &hdr + hdr_pos, sizeof(hdr) - hdr_pos); + n = read(reinterpret_cast(&hdr) + hdr_pos, sizeof(hdr) - hdr_pos); if (n <= 0) { return false; } @@ -93,7 +93,7 @@ StreamDevice::partial_read() } } - switch ((StreamMsgType) hdr.type) { + switch (static_cast(hdr.type)) { case STREAM_TYPE_FORMAT: if (hdr.size != sizeof(StreamMsgFormat)) { handled = handle_msg_invalid("Wrong size for StreamMsgFormat"); @@ -142,7 +142,7 @@ StreamDevice::partial_read() // Currently the only message that requires resizing is the cursor shape, // which is not expected to be sent so often. if (msg_len > sizeof(*msg)) { - msg = (StreamDevice::AllMessages*) g_realloc(msg, sizeof(*msg)); + msg = static_cast(g_realloc(msg, sizeof(*msg))); msg_len = sizeof(*msg); } } @@ -183,12 +183,12 @@ StreamDevice::handle_msg_invalid(const char *error_msg) write_buffer_get_server(total_size, false); buf->buf_used = total_size; - auto const header = (StreamDevHeader *)buf->buf; + auto const header = reinterpret_cast(buf->buf); fill_dev_hdr(header, STREAM_TYPE_NOTIFY_ERROR, msg_size); - auto const error = (StreamMsgNotifyError *)(header+1); + auto const error = reinterpret_cast(header + 1); error->error_code = GUINT32_TO_LE(0); - strcpy((char *) error->msg, error_msg); + strcpy(reinterpret_cast(error->msg), error_msg); write_buffer_add(buf); @@ -226,7 +226,7 @@ StreamDevice::handle_msg_device_display_info() spice_extra_assert(hdr.type == STREAM_TYPE_DEVICE_DISPLAY_INFO); if (msg_len < hdr.size) { - msg = (StreamDevice::AllMessages*) g_realloc(msg, hdr.size); + msg = static_cast(g_realloc(msg, hdr.size)); msg_len = hdr.size; } @@ -255,15 +255,15 @@ StreamDevice::handle_msg_device_display_info() return true; } - if (display_info_msg->device_address + device_address_len > (uint8_t*) msg + hdr.size) { + if (display_info_msg->device_address + device_address_len > + reinterpret_cast(msg) + hdr.size) { g_warning("Malformed DeviceDisplayInfo message, device_address length (%zu) " "goes beyond the end of the message, ignoring.", device_address_len); return true; } memcpy(device_display_info.device_address, - (char*) display_info_msg->device_address, - device_address_len); + reinterpret_cast(display_info_msg->device_address), device_address_len); // make sure the string is terminated device_display_info.device_address[device_address_len - 1] = '\0'; @@ -332,7 +332,7 @@ StreamDevice::handle_msg_data() hdr.size, frame_mmtime); if (msg_len < hdr.size) { g_free(msg); - msg = (StreamDevice::AllMessages*) g_malloc(hdr.size); + msg = static_cast(g_malloc(hdr.size)); msg_len = hdr.size; } } @@ -414,7 +414,7 @@ stream_msg_cursor_set_to_cursor_cmd(const StreamMsgCursorSet *msg, size_t msg_si return red::shared_ptr(); } cursor->data_size = size_required; - cursor->data = (uint8_t*) g_memdup2(msg->data, size_required); + cursor->data = static_cast(g_memdup2(msg->data, size_required)); return cmd; } @@ -437,7 +437,7 @@ StreamDevice::handle_msg_cursor_set() // read part of the message till we get all if (msg_len < hdr.size) { - msg = (StreamDevice::AllMessages*) g_realloc(msg, hdr.size); + msg = static_cast(g_realloc(msg, hdr.size)); msg_len = hdr.size; } int n = read(msg->buf + msg_pos, hdr.size - msg_pos); @@ -493,7 +493,7 @@ void StreamDevice::stream_start(void *opaque, StreamMsgStartStop *start, StreamChannel *stream_channel G_GNUC_UNUSED) { - auto dev = (StreamDevice *) opaque; + auto dev = static_cast(opaque); if (!dev->opened) { return; @@ -506,7 +506,7 @@ StreamDevice::stream_start(void *opaque, StreamMsgStartStop *start, dev->write_buffer_get_server(total_size, false); buf->buf_used = total_size; - auto hdr = (StreamDevHeader *)buf->buf; + auto hdr = reinterpret_cast(buf->buf); fill_dev_hdr(hdr, STREAM_TYPE_START_STOP, msg_size); memcpy(&hdr[1], start, msg_size); @@ -518,7 +518,7 @@ void StreamDevice::stream_queue_stat(void *opaque, const StreamQueueStat *stats G_GNUC_UNUSED, StreamChannel *stream_channel G_GNUC_UNUSED) { - auto dev = (StreamDevice *) opaque; + auto dev = static_cast(opaque); if (!dev->opened) { return; @@ -559,7 +559,7 @@ stream_device_connect(RedsState *reds, SpiceCharDeviceInstance *sin) StreamDevice::StreamDevice(RedsState *reds, SpiceCharDeviceInstance *sin): RedCharDevice(reds, sin, 0, 0) { - msg = (StreamDevice::AllMessages*) g_malloc(sizeof(*msg)); + msg = static_cast(g_malloc(sizeof(*msg))); msg_len = sizeof(*msg); } @@ -630,10 +630,10 @@ send_capabilities(RedCharDevice *char_dev) char_dev->write_buffer_get_server(total_size, false); buf->buf_used = total_size; - auto const hdr = (StreamDevHeader *)buf->buf; + auto const hdr = reinterpret_cast(buf->buf); fill_dev_hdr(hdr, STREAM_TYPE_CAPABILITIES, msg_size); - auto const caps = (StreamMsgCapabilities *)(hdr+1); + auto const caps = reinterpret_cast(hdr + 1); memset(caps, 0, msg_size); char_dev->write_buffer_add(buf); diff --git a/server/red-stream.cpp b/server/red-stream.cpp index 6ce5dc62..2c45299c 100644 --- a/server/red-stream.cpp +++ b/server/red-stream.cpp @@ -455,15 +455,15 @@ static void red_stream_set_socket(RedStream *stream, int socket) /* deprecated fields. Filling them for backward compatibility */ stream->priv->info->llen = sizeof(stream->priv->info->laddr); stream->priv->info->plen = sizeof(stream->priv->info->paddr); - getsockname(stream->socket, (struct sockaddr*)(&stream->priv->info->laddr), &stream->priv->info->llen); - getpeername(stream->socket, (struct sockaddr*)(&stream->priv->info->paddr), &stream->priv->info->plen); + getsockname(stream->socket, &stream->priv->info->laddr, &stream->priv->info->llen); + getpeername(stream->socket, &stream->priv->info->paddr, &stream->priv->info->plen); stream->priv->info->flags |= SPICE_CHANNEL_EVENT_FLAG_ADDR_EXT; stream->priv->info->llen_ext = sizeof(stream->priv->info->laddr_ext); stream->priv->info->plen_ext = sizeof(stream->priv->info->paddr_ext); - getsockname(stream->socket, (struct sockaddr*)(&stream->priv->info->laddr_ext), + getsockname(stream->socket, reinterpret_cast(&stream->priv->info->laddr_ext), &stream->priv->info->llen_ext); - getpeername(stream->socket, (struct sockaddr*)(&stream->priv->info->paddr_ext), + getpeername(stream->socket, reinterpret_cast(&stream->priv->info->paddr_ext), &stream->priv->info->plen_ext); } @@ -483,8 +483,8 @@ RedStream *red_stream_new(RedsState *reds, int socket) { RedStream *stream; - stream = (RedStream*) g_malloc0(sizeof(RedStream) + sizeof(RedStreamPrivate)); - stream->priv = (RedStreamPrivate *)(stream+1); + stream = static_cast(g_malloc0(sizeof(RedStream) + sizeof(RedStreamPrivate))); + stream->priv = reinterpret_cast(stream + 1); stream->priv->info = g_new0(SpiceChannelEventInfo, 1); stream->priv->reds = reds; stream->priv->core = reds_get_core_interface(reds); @@ -1173,7 +1173,7 @@ static ssize_t stream_websocket_read(RedStream *s, void *buf, size_t size) int len; do { - len = websocket_read(s->priv->ws, (uint8_t *) buf, size, &flags); + len = websocket_read(s->priv->ws, static_cast(buf), size, &flags); } while (len == 0 && flags != 0); return len; } @@ -1200,10 +1200,10 @@ bool red_stream_is_websocket(RedStream *stream, const void *buf, size_t len) return false; } - stream->priv->ws = websocket_new(buf, len, stream, - (websocket_read_cb_t) stream->priv->read, - (websocket_write_cb_t) stream->priv->write, - (websocket_writev_cb_t) stream->priv->writev); + stream->priv->ws = + websocket_new(buf, len, stream, reinterpret_cast(stream->priv->read), + reinterpret_cast(stream->priv->write), + reinterpret_cast(stream->priv->writev)); if (stream->priv->ws) { stream->priv->read = stream_websocket_read; stream->priv->write = stream_websocket_write; diff --git a/server/red-worker.cpp b/server/red-worker.cpp index 86580f46..912b7d55 100644 --- a/server/red-worker.cpp +++ b/server/red-worker.cpp @@ -397,9 +397,8 @@ static void dev_create_primary_surface(RedWorker *worker, uint32_t surface_id, return; } - line_0 = (uint8_t*)memslot_get_virt(&worker->mem_slots, surface.mem, - surface.height * abs(surface.stride), - surface.group_id); + line_0 = static_cast(memslot_get_virt( + &worker->mem_slots, surface.mem, surface.height * abs(surface.stride), surface.group_id)); if (line_0 == nullptr) { return; } @@ -409,7 +408,7 @@ static void dev_create_primary_surface(RedWorker *worker, uint32_t surface_id, } if (surface.stride < 0) { - line_0 -= (int32_t)(surface.stride * (surface.height -1)); + line_0 -= static_cast(surface.stride * (surface.height - 1)); } display_channel_create_surface(display, 0, surface.width, surface.height, surface.stride, surface.format, @@ -599,9 +598,8 @@ handle_dev_monitors_config_async(RedWorker* worker, RedWorkerMessageMonitorsConf { uint16_t count, max_allowed; const QXLMonitorsConfig *dev_monitors_config = - (QXLMonitorsConfig*)memslot_get_virt(&worker->mem_slots, msg->monitors_config, - qxl_monitors_config_size(1), - msg->group_id); + static_cast(memslot_get_virt( + &worker->mem_slots, msg->monitors_config, qxl_monitors_config_size(1), msg->group_id)); if (dev_monitors_config == nullptr) { /* TODO: raise guest bug (requires added QXL interface) */ @@ -622,10 +620,8 @@ handle_dev_monitors_config_async(RedWorker* worker, RedWorkerMessageMonitorsConf goto async_complete; } /* get pointer again to check virtual size */ - dev_monitors_config = - (QXLMonitorsConfig*)memslot_get_virt(&worker->mem_slots, msg->monitors_config, - qxl_monitors_config_size(count), - msg->group_id); + dev_monitors_config = static_cast(memslot_get_virt( + &worker->mem_slots, msg->monitors_config, qxl_monitors_config_size(count), msg->group_id)); if (dev_monitors_config == nullptr) { /* TODO: raise guest bug (requires added QXL interface) */ goto async_complete; @@ -756,7 +752,7 @@ handle_dev_loadvm_commands(RedWorker* worker, RedWorkerMessageLoadvmCommands* ms static void worker_dispatcher_record(void *opaque, uint32_t message_type, void *payload) { - auto worker = (RedWorker*) opaque; + auto worker = static_cast(opaque); red_record_event(worker->record, 1, message_type); } @@ -1008,7 +1004,7 @@ RedWorker* red_worker_new(QXLInstance *qxl) static void *red_worker_main(void *arg) { - auto worker = (RedWorker *) arg; + auto worker = static_cast(arg); spice_debug("begin"); #if defined(__APPLE__) diff --git a/server/reds.cpp b/server/reds.cpp index 7ed211db..11eb4cb2 100644 --- a/server/reds.cpp +++ b/server/reds.cpp @@ -398,7 +398,7 @@ static void reds_reset_vdp(RedsState *reds) SpiceCharDeviceInterface *sif; dev->priv->read_state = VDI_PORT_READ_STATE_READ_HEADER; - dev->priv->receive_pos = (uint8_t *)&dev->priv->vdi_chunk_header; + dev->priv->receive_pos = reinterpret_cast(&dev->priv->vdi_chunk_header); dev->priv->receive_len = sizeof(dev->priv->vdi_chunk_header); dev->priv->message_receive_len = 0; dev->priv->current_read_buf.reset(); @@ -452,7 +452,7 @@ static RedCharDeviceWriteBuffer *vdagent_new_write_buffer(RedCharDeviceVDIPort * } char_dev_buf->buf_used = total_msg_size; - auto internal_buf = (VDInternalBuf *)char_dev_buf->buf; + auto internal_buf = reinterpret_cast(char_dev_buf->buf); internal_buf->chunk_header.port = VDP_SERVER_PORT; internal_buf->chunk_header.size = sizeof(VDAgentMessage) + size; internal_buf->header.protocol = VD_AGENT_PROTOCOL; @@ -504,7 +504,7 @@ void reds_client_disconnect(RedsState *reds, RedClient *client) /* note that client might be NULL, if the vdagent was once * up and than was removed */ - auto client_opaque = (RedCharDeviceClientOpaque *) client; + auto client_opaque = reinterpret_cast(client); if (reds->agent_dev->client_exists(client_opaque)) { reds->agent_dev->client_remove(client_opaque); } @@ -707,7 +707,7 @@ static void reds_adjust_agent_capabilities(RedsState *reds, VDAgentMessage *mess if (message->type != VD_AGENT_ANNOUNCE_CAPABILITIES) { return; } - capabilities = (VDAgentAnnounceCapabilities *) message->data; + capabilities = reinterpret_cast(message->data); if (!reds->config->agent_copypaste) { VD_AGENT_CLEAR_CAPABILITY(capabilities->caps, VD_AGENT_CAP_CLIPBOARD); @@ -773,14 +773,15 @@ RedCharDeviceVDIPort::read_one_msg_from_device() priv->receive_pos = nullptr; if (priv->message_receive_len == 0) { priv->read_state = VDI_PORT_READ_STATE_READ_HEADER; - priv->receive_pos = (uint8_t *)&priv->vdi_chunk_header; + priv->receive_pos = reinterpret_cast(&priv->vdi_chunk_header); priv->receive_len = sizeof(priv->vdi_chunk_header); } else { priv->read_state = VDI_PORT_READ_STATE_GET_BUFF; } switch (vdi_port_read_buf_process(this, *dispatch_buf)) { case AGENT_MSG_FILTER_OK: - reds_adjust_agent_capabilities(reds, (VDAgentMessage *) dispatch_buf->data); + reds_adjust_agent_capabilities( + reds, reinterpret_cast(dispatch_buf->data)); return dispatch_buf; case AGENT_MSG_FILTER_PROTO_ERROR: reds_agent_remove(reds); @@ -828,7 +829,8 @@ void reds_marshall_device_display_info(RedsState *reds, SpiceMarshaller *m) spice_marshaller_add_uint32(m, info->stream_id); spice_marshaller_add_uint32(m, info->device_display_id); spice_marshaller_add_uint32(m, device_address_len); - spice_marshaller_add(m, (const uint8_t*) (void*) info->device_address, device_address_len); + spice_marshaller_add(m, reinterpret_cast(info->device_address), + device_address_len); ++device_count; g_debug(" (stream) channel_id: %u monitor_id: %u, device_address: %s, " @@ -865,7 +867,7 @@ void reds_send_device_display_info(RedsState *reds) return; } - auto internal_buf = (VDInternalBuf *)char_dev_buf->buf; + auto internal_buf = reinterpret_cast(char_dev_buf->buf); int free_info; size_t len_info; @@ -884,7 +886,7 @@ void reds_send_device_display_info(RedsState *reds) /* after calling this, we unref the message, and the ref is in the instance side */ void RedCharDeviceVDIPort::send_msg_to_client(RedPipeItem *msg, RedCharDeviceClientOpaque *opaque) { - auto client = (RedClient *) opaque; + auto client = reinterpret_cast(opaque); auto agent_data_buf = static_cast(msg); client->get_main()->push_agent_data(red::shared_ptr(agent_data_buf)); @@ -892,7 +894,7 @@ void RedCharDeviceVDIPort::send_msg_to_client(RedPipeItem *msg, RedCharDeviceCli void RedCharDeviceVDIPort::send_tokens_to_client(RedCharDeviceClientOpaque *opaque, uint32_t tokens) { - auto client = (RedClient *) opaque; + auto client = reinterpret_cast(opaque); client->get_main()->push_agent_tokens(tokens); } @@ -913,7 +915,7 @@ void RedCharDeviceVDIPort::on_free_self_token() void RedCharDeviceVDIPort::remove_client(RedCharDeviceClientOpaque *opaque) { - auto client = (RedClient *) opaque; + auto client = reinterpret_cast(opaque); client->get_main()->shutdown(); } @@ -942,7 +944,7 @@ void reds_handle_agent_mouse_event(RedsState *reds, const VDAgentMouseState *mou reds->pending_mouse_event = FALSE; - auto internal_buf = (VDInternalBuf *)char_dev_buf->buf; + auto internal_buf = reinterpret_cast(char_dev_buf->buf); internal_buf->u.mouse_state = *mouse_state; reds->agent_dev->write_buffer_add(char_dev_buf); @@ -991,8 +993,8 @@ SpiceMsgChannels *reds_msg_channels_new(RedsState *reds) spice_assert(reds != nullptr); - channels_info = (SpiceMsgChannels *)g_malloc(sizeof(SpiceMsgChannels) - + reds->channels.size() * sizeof(SpiceChannelId)); + channels_info = static_cast( + g_malloc(sizeof(SpiceMsgChannels) + reds->channels.size() * sizeof(SpiceChannelId))); reds_fill_channels(reds, channels_info); @@ -1017,7 +1019,7 @@ void reds_on_main_agent_start(RedsState *reds, MainChannelClient *mcc, uint32_t * and vice versa, the sending from the server to the client won't have * flow control, but will have no other problem. */ - auto client_opaque = (RedCharDeviceClientOpaque *) client; + auto client_opaque = reinterpret_cast(client); if (!dev_state->client_exists(client_opaque)) { int client_added; @@ -1051,8 +1053,8 @@ void reds_on_main_agent_tokens(RedsState *reds, MainChannelClient *mcc, uint32_t return; } spice_assert(reds->vdagent->st); - reds->vdagent->st->send_to_client_tokens_add((RedCharDeviceClientOpaque *)client, - num_tokens); + reds->vdagent->st->send_to_client_tokens_add( + reinterpret_cast(client), num_tokens); } uint8_t *reds_get_agent_data_buffer(RedsState *reds, MainChannelClient *mcc, size_t size) @@ -1068,14 +1070,13 @@ uint8_t *reds_get_agent_data_buffer(RedsState *reds, MainChannelClient *mcc, siz * In such case, we will receive and discard the msgs (reds_reset_vdp takes care * of setting dev->write_filter.result = AGENT_MSG_FILTER_DISCARD). */ - return (uint8_t*) g_malloc(size); + return static_cast(g_malloc(size)); } spice_assert(dev->priv->recv_from_client_buf == nullptr); client = mcc->get_client(); - dev->priv->recv_from_client_buf = - dev->write_buffer_get_client((RedCharDeviceClientOpaque *)client, - size + sizeof(VDIChunkHeader)); + dev->priv->recv_from_client_buf = dev->write_buffer_get_client( + reinterpret_cast(client), size + sizeof(VDIChunkHeader)); /* check if buffer was allocated, as flow control is enabled for * this device this is a normal condition */ if (!dev->priv->recv_from_client_buf) { @@ -1127,7 +1128,7 @@ static void reds_on_main_agent_monitors_config(RedsState *reds, spice_debug("not enough data yet. %" G_GSSIZE_FORMAT, cmc->offset); return; } - msg_header = (VDAgentMessage *)cmc->buffer; + msg_header = reinterpret_cast(cmc->buffer); msg_size = GUINT32_FROM_LE(msg_header->size); if (msg_size > MAX_MONITOR_CONFIG_SIZE) { goto overflow; @@ -1143,9 +1144,9 @@ static void reds_on_main_agent_monitors_config(RedsState *reds, msg_header->opaque = GUINT64_FROM_LE(msg_header->opaque); msg_header->size = GUINT32_FROM_LE(msg_header->size); - monitors_config = (VDAgentMonitorsConfig *)(cmc->buffer + sizeof(*msg_header)); - if (agent_check_message(msg_header, (uint8_t *) monitors_config, - nullptr, 0) != AGENT_CHECK_NO_ERROR) { + monitors_config = reinterpret_cast(cmc->buffer + sizeof(*msg_header)); + if (agent_check_message(msg_header, reinterpret_cast(monitors_config), nullptr, 0) != + AGENT_CHECK_NO_ERROR) { goto overflow; } spice_debug("monitors_config->num_of_monitors: %d", monitors_config->num_of_monitors); @@ -1167,7 +1168,7 @@ void reds_on_main_agent_data(RedsState *reds, MainChannelClient *mcc, const void AgentMsgFilterResult res; res = agent_msg_filter_process_data(&dev->priv->write_filter, - (const uint8_t*) message, size); + static_cast(message), size); switch (res) { case AGENT_MSG_FILTER_OK: break; @@ -1184,7 +1185,7 @@ void reds_on_main_agent_data(RedsState *reds, MainChannelClient *mcc, const void spice_assert(dev->priv->recv_from_client_buf); spice_assert(message == dev->priv->recv_from_client_buf->buf + sizeof(VDIChunkHeader)); // TODO - start tracking agent data per channel - header = (VDIChunkHeader *)dev->priv->recv_from_client_buf->buf; + header = reinterpret_cast(dev->priv->recv_from_client_buf->buf); header->port = VDP_CLIENT_PORT; header->size = size; dev->priv->recv_from_client_buf->buf_used = sizeof(VDIChunkHeader) + size; @@ -1203,7 +1204,7 @@ void reds_on_main_migrate_connected(RedsState *reds, int seamless) void reds_on_main_mouse_mode_request(RedsState *reds, void *message, size_t size) { - switch (((SpiceMsgcMainMouseModeRequest *)message)->mode) { + switch ((static_cast(message))->mode) { case SPICE_MOUSE_MODE_CLIENT: if (reds->is_client_mouse_allowed) { reds_set_mouse_mode(reds, SPICE_MOUSE_MODE_CLIENT); @@ -1247,7 +1248,8 @@ void reds_on_main_channel_migrate(RedsState *reds, MainChannelClient *mcc) read_buf->len = read_data_len; switch (vdi_port_read_buf_process(agent_dev, *read_buf)) { case AGENT_MSG_FILTER_OK: - reds_adjust_agent_capabilities(reds, (VDAgentMessage *)read_buf->data); + reds_adjust_agent_capabilities(reds, + reinterpret_cast(read_buf->data)); mcc->push_agent_data(read_buf); break; case AGENT_MSG_FILTER_PROTO_ERROR: @@ -1299,8 +1301,9 @@ void reds_marshall_migrate_data(RedsState *reds, SpiceMarshaller *m) /* agent to client partial msg */ if (agent_dev->priv->read_state == VDI_PORT_READ_STATE_READ_HEADER) { - mig_data.agent2client.chunk_header_size = agent_dev->priv->receive_pos - - (uint8_t *)&agent_dev->priv->vdi_chunk_header; + mig_data.agent2client.chunk_header_size = + agent_dev->priv->receive_pos - + reinterpret_cast(&agent_dev->priv->vdi_chunk_header); mig_data.agent2client.msg_header_done = FALSE; mig_data.agent2client.msg_header_partial_len = 0; @@ -1322,8 +1325,7 @@ void reds_marshall_migrate_data(RedsState *reds, SpiceMarshaller *m) } } spice_marshaller_add_uint32(m, mig_data.agent2client.chunk_header_size); - spice_marshaller_add(m, - (uint8_t *)&mig_data.agent2client.chunk_header, + spice_marshaller_add(m, reinterpret_cast(&mig_data.agent2client.chunk_header), sizeof(VDIChunkHeader)); spice_marshaller_add_uint8(m, mig_data.agent2client.msg_header_done); spice_marshaller_add_uint32(m, mig_data.agent2client.msg_header_partial_len); @@ -1357,7 +1359,8 @@ static int reds_agent_state_restore(RedsState *reds, SpiceMigrateDataMain *mig_d chunk_header_remaining = sizeof(VDIChunkHeader) - mig_data->agent2client.chunk_header_size; if (chunk_header_remaining) { agent_dev->priv->read_state = VDI_PORT_READ_STATE_READ_HEADER; - agent_dev->priv->receive_pos = (uint8_t *)&agent_dev->priv->vdi_chunk_header + + agent_dev->priv->receive_pos = + reinterpret_cast(&agent_dev->priv->vdi_chunk_header) + mig_data->agent2client.chunk_header_size; agent_dev->priv->receive_len = chunk_header_remaining; } else { @@ -1373,8 +1376,9 @@ static int reds_agent_state_restore(RedsState *reds, SpiceMigrateDataMain *mig_d agent_dev->priv->read_state = VDI_PORT_READ_STATE_READ_DATA; agent_dev->priv->current_read_buf = vdi_port_get_read_buf(agent_dev); spice_assert(agent_dev->priv->current_read_buf); - partial_msg_header = (uint8_t *)mig_data + mig_data->agent2client.msg_header_ptr - - sizeof(SpiceMiniDataHeader); + partial_msg_header = reinterpret_cast(mig_data) + + mig_data->agent2client.msg_header_ptr - + sizeof(SpiceMiniDataHeader); memcpy(agent_dev->priv->current_read_buf->data, partial_msg_header, mig_data->agent2client.msg_header_partial_len); @@ -1394,7 +1398,8 @@ static int reds_agent_state_restore(RedsState *reds, SpiceMigrateDataMain *mig_d agent_dev->priv->current_read_buf.reset(); agent_dev->priv->receive_pos = nullptr; agent_dev->priv->read_filter.msg_data_to_read = mig_data->agent2client.msg_remaining; - agent_dev->priv->read_filter.result = (AgentMsgFilterResult) mig_data->agent2client.msg_filter_result; + agent_dev->priv->read_filter.result = + static_cast(mig_data->agent2client.msg_filter_result); } agent_dev->priv->read_filter.discard_all = FALSE; @@ -1402,7 +1407,8 @@ static int reds_agent_state_restore(RedsState *reds, SpiceMigrateDataMain *mig_d agent_dev->priv->client_agent_started = mig_data->client_agent_started; agent_dev->priv->write_filter.msg_data_to_read = mig_data->client2agent.msg_remaining; - agent_dev->priv->write_filter.result = (AgentMsgFilterResult) mig_data->client2agent.msg_filter_result; + agent_dev->priv->write_filter.result = + static_cast(mig_data->client2agent.msg_filter_result); spice_debug("to agent filter: discard all %d, wait_msg %u, msg_filter_result %d", agent_dev->priv->write_filter.discard_all, @@ -1455,13 +1461,13 @@ bool reds_handle_migrate_data(RedsState *reds, MainChannelClient *mcc, /* restore agent state when the agent gets attached */ spice_debug("saving mig_data"); spice_assert(agent_dev->priv->plug_generation == 0); - agent_dev->priv->mig_data = (SpiceMigrateDataMain*) g_memdup2(mig_data, size); + agent_dev->priv->mig_data = + static_cast(g_memdup2(mig_data, size)); } } else { spice_debug("agent was not attached on the source host"); if (reds->vdagent) { - auto client_opaque = - (RedCharDeviceClientOpaque *) mcc->get_client(); + auto client_opaque = reinterpret_cast(mcc->get_client()); /* red_char_device_client_remove disables waiting for migration data */ agent_dev->client_remove(client_opaque); reds->main_channel->push_agent_connected(); @@ -1484,9 +1490,9 @@ static void reds_channel_init_auth_caps(RedLinkInfo *link, RedChannel *channel) static const uint32_t *red_link_info_get_caps(const RedLinkInfo *link) { - const auto caps_start = (const uint8_t *)link->link_mess; + const auto caps_start = reinterpret_cast(link->link_mess); - return (const uint32_t *)(caps_start + link->link_mess->caps_offset); + return reinterpret_cast(caps_start + link->link_mess->caps_offset); } static bool red_link_info_test_capability(const RedLinkInfo *link, uint32_t cap) @@ -1654,7 +1660,7 @@ static RedsMigTargetClient* reds_mig_target_client_find(RedsState *reds, RedClie GList *l; for (l = reds->mig_target_clients; l != nullptr; l = l->next) { - auto mig_client = (RedsMigTargetClient*) l->data; + auto mig_client = static_cast(l->data); if (mig_client->client == client) { return mig_client; @@ -1733,19 +1739,20 @@ static void red_channel_capabilities_init_from_link_message(RedChannelCapabilities *caps, const SpiceLinkMess *link_mess) { - const uint8_t *raw_caps = (const uint8_t *)link_mess + link_mess->caps_offset; + const uint8_t *raw_caps = reinterpret_cast(link_mess) + link_mess->caps_offset; caps->num_common_caps = link_mess->num_common_caps; caps->common_caps = nullptr; if (caps->num_common_caps) { - caps->common_caps = (uint32_t*) g_memdup2(raw_caps, - link_mess->num_common_caps * sizeof(uint32_t)); + caps->common_caps = static_cast( + g_memdup2(raw_caps, link_mess->num_common_caps * sizeof(uint32_t))); } caps->num_caps = link_mess->num_channel_caps; caps->caps = nullptr; if (link_mess->num_channel_caps) { - caps->caps = (uint32_t*) g_memdup2(raw_caps + link_mess->num_common_caps * sizeof(uint32_t), - link_mess->num_channel_caps * sizeof(uint32_t)); + caps->caps = static_cast( + g_memdup2(raw_caps + link_mess->num_common_caps * sizeof(uint32_t), + link_mess->num_channel_caps * sizeof(uint32_t))); } } @@ -1882,7 +1889,7 @@ static bool reds_link_mig_target_channels(RedsState *reds, RedClient *client) /* Each channel should check if we are during migration, and * act accordingly. */ for(item = mig_client->pending_links; item != nullptr; item = item->next) { - auto mig_link = (RedsMigPendingLink*) item->data; + auto mig_link = static_cast(item->data); RedChannel *channel; channel = reds_find_channel(reds, mig_link->link_msg->channel_type, @@ -2010,7 +2017,7 @@ static void reds_handle_link(RedLinkInfo *link) static void reds_handle_ticket(void *opaque) { - auto link = (RedLinkInfo *)opaque; + auto link = static_cast(opaque); RedsState *reds = link->reds; char *password; int password_size; @@ -2021,12 +2028,12 @@ static void reds_handle_ticket(void *opaque) RSA_size(link->tiTicketing.rsa), SPICE_MAX_PASSWORD_LENGTH); } - password = (char *) alloca(RSA_size(link->tiTicketing.rsa) + 1); - password_size = RSA_private_decrypt(link->tiTicketing.rsa_size, - link->tiTicketing.encrypted_ticket.encrypted_data, - (unsigned char *)password, - link->tiTicketing.rsa, - RSA_PKCS1_OAEP_PADDING); + password = static_cast(alloca(RSA_size(link->tiTicketing.rsa) + 1)); + password_size = + RSA_private_decrypt(link->tiTicketing.rsa_size, + link->tiTicketing.encrypted_ticket.encrypted_data, + reinterpret_cast(password), + link->tiTicketing.rsa, RSA_PKCS1_OAEP_PADDING); if (password_size == -1) { spice_warning("failed to decrypt RSA encrypted password"); red_dump_openssl_errors(); @@ -2068,9 +2075,10 @@ error: static void reds_get_spice_ticket(RedLinkInfo *link) { - red_stream_async_read(link->stream, - (uint8_t *)&link->tiTicketing.encrypted_ticket.encrypted_data, - link->tiTicketing.rsa_size, reds_handle_ticket, link); + red_stream_async_read( + link->stream, + reinterpret_cast(&link->tiTicketing.encrypted_ticket.encrypted_data), + link->tiTicketing.rsa_size, reds_handle_ticket, link); } #if HAVE_SASL @@ -2105,7 +2113,7 @@ static void reds_start_auth_sasl(RedLinkInfo *link) static void reds_handle_auth_mechanism(void *opaque) { - auto link = (RedLinkInfo *)opaque; + auto link = static_cast(opaque); RedsState *reds = link->reds; spice_debug("Auth method: %d", link->auth_mechanism.auth_mechanism); @@ -2141,7 +2149,7 @@ static int reds_security_check(RedLinkInfo *link) static void reds_handle_read_link_done(void *opaque) { - auto link = (RedLinkInfo *)opaque; + auto link = static_cast(opaque); RedsState *reds = link->reds; SpiceLinkMess *link_mess = link->link_mess; uint32_t num_caps; @@ -2163,7 +2171,8 @@ static void reds_handle_read_link_done(void *opaque) } num_caps = link_mess->num_common_caps + link_mess->num_channel_caps; - caps = (uint32_t *)((uint8_t *)link_mess + link_mess->caps_offset); + caps = reinterpret_cast(reinterpret_cast(link_mess) + + link_mess->caps_offset); if (num_caps && (num_caps * sizeof(uint32_t) + link_mess->caps_offset > link->link_header.size || @@ -2205,17 +2214,14 @@ static void reds_handle_read_link_done(void *opaque) spice_warning("Peer doesn't support AUTH selection"); reds_get_spice_ticket(link); } else { - red_stream_async_read(link->stream, - (uint8_t *)&link->auth_mechanism, - sizeof(SpiceLinkAuthMechanism), - reds_handle_auth_mechanism, - link); + red_stream_async_read(link->stream, reinterpret_cast(&link->auth_mechanism), + sizeof(SpiceLinkAuthMechanism), reds_handle_auth_mechanism, link); } } static void reds_handle_link_error(void *opaque, int err) { - auto link = (RedLinkInfo *)opaque; + auto link = static_cast(opaque); switch (err) { case 0: case EPIPE: @@ -2230,7 +2236,7 @@ static void reds_handle_link_error(void *opaque, int err) static void reds_handle_new_link(RedLinkInfo *link); static void reds_handle_read_header_done(void *opaque) { - auto link = (RedLinkInfo *)opaque; + auto link = static_cast(opaque); SpiceLinkHeader *header = &link->link_header; header->major_version = GUINT32_FROM_LE(header->major_version); @@ -2255,18 +2261,15 @@ static void reds_handle_read_header_done(void *opaque) return; } - link->link_mess = (SpiceLinkMess*) g_malloc(header->size); + link->link_mess = static_cast(g_malloc(header->size)); - red_stream_async_read(link->stream, - (uint8_t *)link->link_mess, - header->size, - reds_handle_read_link_done, - link); + red_stream_async_read(link->stream, reinterpret_cast(link->link_mess), header->size, + reds_handle_read_link_done, link); } static void reds_handle_read_magic_done(void *opaque) { - auto link = (RedLinkInfo *)opaque; + auto link = static_cast(opaque); const SpiceLinkHeader *header = &link->link_header; if (header->magic != SPICE_MAGIC) { @@ -2288,25 +2291,21 @@ static void reds_handle_read_magic_done(void *opaque) } red_stream_async_read(link->stream, - ((uint8_t *)&link->link_header) + sizeof(header->magic), + reinterpret_cast(&link->link_header) + sizeof(header->magic), sizeof(SpiceLinkHeader) - sizeof(header->magic), - reds_handle_read_header_done, - link); + reds_handle_read_header_done, link); } static void reds_handle_new_link(RedLinkInfo *link) { red_stream_set_async_error_handler(link->stream, reds_handle_link_error); - red_stream_async_read(link->stream, - (uint8_t *)&link->link_header, - sizeof(link->link_header.magic), - reds_handle_read_magic_done, - link); + red_stream_async_read(link->stream, reinterpret_cast(&link->link_header), + sizeof(link->link_header.magic), reds_handle_read_magic_done, link); } static void reds_handle_ssl_accept(int fd, int event, void *data) { - auto link = (RedLinkInfo *)data; + auto link = static_cast(data); RedStreamSslStatus return_code = red_stream_ssl_accept(link->stream); switch (return_code) { @@ -2396,7 +2395,7 @@ error: static void reds_accept_ssl_connection(int fd, int event, void *data) { - auto reds = (RedsState*) data; + auto reds = static_cast(data); RedLinkInfo *link; int socket; @@ -2413,7 +2412,7 @@ static void reds_accept_ssl_connection(int fd, int event, void *data) static void reds_accept(int fd, int event, void *data) { - auto reds = (RedsState*) data; + auto reds = static_cast(data); int socket; if ((socket = accept(fd, nullptr, nullptr)) == -1) { @@ -2481,7 +2480,7 @@ static int reds_init_socket(const char *addr, int portnr, int family) } else { unlink(local.sun_path); } - if (bind(slisten, (struct sockaddr *)&local, len) == -1) { + if (bind(slisten, reinterpret_cast(&local), len) == -1) { perror("bind"); socket_close(slisten); return -1; @@ -2523,8 +2522,7 @@ static int reds_init_socket(const char *addr, int portnr, int family) if (bind(slisten, e->ai_addr, e->ai_addrlen) == 0) { char uaddr[INET6_ADDRSTRLEN+1]; char uport[33]; - rc = getnameinfo((struct sockaddr*)e->ai_addr,e->ai_addrlen, - uaddr,INET6_ADDRSTRLEN, uport,32, + rc = getnameinfo(e->ai_addr, e->ai_addrlen, uaddr, INET6_ADDRSTRLEN, uport, 32, NI_NUMERICHOST | NI_NUMERICSERV); if (rc == 0) { spice_debug("bound to %s:%s", uaddr, uport); @@ -2666,7 +2664,7 @@ static int load_dh_params(SSL_CTX *ctx, char *file) /*The password code is not thread safe*/ static int ssl_password_cb(char *buf, int size, int flags, void *userdata) { - auto reds = (RedsState*) userdata; + auto reds = static_cast(userdata); char *pass = reds->config->ssl_parameters.keyfile_password; int len = g_strlcpy(buf, pass, size); if (len >= size) { @@ -2806,7 +2804,7 @@ static int reds_init_ssl(RedsState *reds) } } - SSL_CTX_set_session_id_context(reds->ctx, (const unsigned char *)"SPICE", 5); + SSL_CTX_set_session_id_context(reds->ctx, reinterpret_cast("SPICE"), 5); if (strlen(reds->config->ssl_parameters.ciphersuite) > 0) { if (!SSL_CTX_set_cipher_list(reds->ctx, reds->config->ssl_parameters.ciphersuite)) { return -1; @@ -2829,7 +2827,7 @@ SPICE_DESTRUCTOR_FUNC(reds_exit) pthread_mutex_lock(&global_reds_lock); for (l = servers; l != nullptr; l = l->next) { - auto reds = (RedsState*) l->data; + auto reds = static_cast(l->data); reds_cleanup(reds); } pthread_mutex_unlock(&global_reds_lock); @@ -3039,8 +3037,7 @@ attach_to_red_agent(RedsState *reds, SpiceCharDeviceInstance *sin) * 2.b If this happens second ==> we already have spice migrate data * then restore state */ - auto client_opaque = - (RedCharDeviceClientOpaque *) reds_get_client(reds); + auto client_opaque = reinterpret_cast(reds_get_client(reds)); if (!dev->client_exists(client_opaque)) { int client_added; @@ -3305,7 +3302,8 @@ SPICE_GNUC_VISIBLE int spice_server_add_interface(SpiceServer *reds, return -1; } reds->migration_interface = SPICE_UPCAST(SpiceMigrateInstance, sin); - reds->migration_interface->st = (SpiceMigrateState *)(intptr_t)1; // dummy pointer + reds->migration_interface->st = + reinterpret_cast(static_cast(1)); // dummy pointer } return 0; @@ -3647,7 +3645,7 @@ static int reds_set_video_codecs_from_string(RedsState *reds, const char *codecs } else { RedVideoCodec new_codec; new_codec.create = video_encoder_procs[encoder_index]; - new_codec.type = (SpiceVideoCodecType) video_codec_names[codec_index].id; + new_codec.type = static_cast(video_codec_names[codec_index].id); new_codec.cap = video_codec_caps[codec_index]; g_array_append_val(video_codecs, new_codec); } @@ -4423,7 +4421,7 @@ RedCharDeviceVDIPort::RedCharDeviceVDIPort(RedsState *reds): RedCharDevice(reds, nullptr, REDS_TOKENS_TO_SEND, REDS_NUM_INTERNAL_AGENT_MESSAGES) { priv->read_state = VDI_PORT_READ_STATE_READ_HEADER; - priv->receive_pos = (uint8_t *)&priv->vdi_chunk_header; + priv->receive_pos = reinterpret_cast(&priv->vdi_chunk_header); priv->receive_len = sizeof(priv->vdi_chunk_header); RedCharDeviceVDIPort *dev = this; diff --git a/server/sound.cpp b/server/sound.cpp index f52042c2..eca2706c 100644 --- a/server/sound.cpp +++ b/server/sound.cpp @@ -236,7 +236,7 @@ static SndChannelClient *snd_channel_get_client(SndChannel *channel) return nullptr; } - return (SndChannelClient*) clients->data; + return static_cast(clients->data); } static RedsState* snd_channel_get_server(SndChannelClient *client) @@ -278,7 +278,7 @@ static bool snd_record_handle_write(RecordChannelClient *record_client, size_t s return false; } - packet = (SpiceMsgcRecordPacket *)message; + packet = static_cast(message); if (record_client->mode == SPICE_AUDIO_DATA_MODE_RAW) { data = packet->data; @@ -339,7 +339,7 @@ bool RecordChannelClient::handle_message(uint16_t type, uint32_t size, void *mes case SPICE_MSGC_RECORD_DATA: return snd_record_handle_write(this, size, message); case SPICE_MSGC_RECORD_MODE: { - auto msg_mode = (SpiceMsgcRecordMode *)message; + auto msg_mode = static_cast(message); SndChannel *channel = get_channel(); mode_time = msg_mode->time; auto new_mode = static_cast(msg_mode->mode); @@ -366,7 +366,7 @@ bool RecordChannelClient::handle_message(uint16_t type, uint32_t size, void *mes } case SPICE_MSGC_RECORD_START_MARK: { - auto mark = (SpiceMsgcRecordStartMark *)message; + auto mark = static_cast(message); start_time = mark->time; break; } @@ -408,8 +408,8 @@ static bool snd_send_volume(SndChannelClient *client, uint32_t cap, int msg) return false; } - vol = (SpiceMsgAudioVolume*) alloca(sizeof (SpiceMsgAudioVolume) + - st->volume_nchannels * sizeof (uint16_t)); + vol = static_cast( + alloca(sizeof(SpiceMsgAudioVolume) + st->volume_nchannels * sizeof(uint16_t))); rcc->init_send_data(msg); vol->nchannels = st->volume_nchannels; for (c = 0; c < st->volume_nchannels; ++c) { @@ -581,17 +581,17 @@ static bool snd_playback_send_write(PlaybackChannelClient *playback_client) spice_marshall_msg_playback_data(m, &msg); if (playback_client->mode == SPICE_AUDIO_DATA_MODE_RAW) { - spice_marshaller_add_by_ref_full(m, (uint8_t *)frame->samples, - snd_codec_frame_size(playback_client->codec) * - sizeof(frame->samples[0]), - PlaybackChannelClient::on_message_marshalled, - playback_client); + spice_marshaller_add_by_ref_full( + m, reinterpret_cast(frame->samples), + snd_codec_frame_size(playback_client->codec) * sizeof(frame->samples[0]), + PlaybackChannelClient::on_message_marshalled, playback_client); } else { int n = sizeof(playback_client->encode_buf); - if (snd_codec_encode(playback_client->codec, (uint8_t *) frame->samples, - snd_codec_frame_size(playback_client->codec) * sizeof(frame->samples[0]), - playback_client->encode_buf, &n) != SND_CODEC_OK) { + if (snd_codec_encode(playback_client->codec, reinterpret_cast(frame->samples), + snd_codec_frame_size(playback_client->codec) * + sizeof(frame->samples[0]), + playback_client->encode_buf, &n) != SND_CODEC_OK) { red_channel_warning(rcc->get_channel(), "encode failed"); rcc->disconnect(); return false; @@ -765,7 +765,7 @@ SndChannelClient::alloc_recv_buf(uint16_t type, uint32_t size) { // If message is too big allocate one, this should never happen if (size > sizeof(receive_buf)) { - return (uint8_t*) g_malloc(size); + return static_cast(g_malloc(size)); } return receive_buf; } @@ -794,7 +794,7 @@ static void snd_channel_set_volume(SndChannel *channel, st->volume_nchannels = nchannels; g_free(st->volume); - st->volume = (uint16_t*) g_memdup2(volume, sizeof(uint16_t) * nchannels); + st->volume = static_cast(g_memdup2(volume, sizeof(uint16_t) * nchannels)); if (!client || nchannels == 0) return; @@ -946,7 +946,7 @@ void snd_set_playback_latency(RedClient *client, uint32_t latency) GList *l; for (l = snd_channels; l != nullptr; l = l->next) { - auto now = (SndChannel*) l->data; + auto now = static_cast(l->data); SndChannelClient *scc = snd_channel_get_client(now); if (now->type() == SPICE_CHANNEL_PLAYBACK && scc && scc->get_client() == client) { @@ -1008,8 +1008,8 @@ PlaybackChannelClient::PlaybackChannelClient(PlaybackChannel *channel, auto desired_mode = snd_desired_audio_mode(playback_compression, channel->frequency, client_can_opus); if (desired_mode != SPICE_AUDIO_DATA_MODE_RAW) { - if (snd_codec_create(&codec, (SpiceAudioDataMode) desired_mode, channel->frequency, - SND_CODEC_ENCODE) == SND_CODEC_OK) { + if (snd_codec_create(&codec, static_cast(desired_mode), + channel->frequency, SND_CODEC_ENCODE) == SND_CODEC_OK) { mode = desired_mode; } else { red_channel_warning(channel, "create encoder failed"); @@ -1281,7 +1281,7 @@ void snd_set_playback_compression(bool on) GList *l; for (l = snd_channels; l != nullptr; l = l->next) { - auto now = (SndChannel*) l->data; + auto now = static_cast(l->data); SndChannelClient *client = snd_channel_get_client(now); if (now->type() == SPICE_CHANNEL_PLAYBACK && client) { PlaybackChannelClient* playback = PLAYBACK_CHANNEL_CLIENT(client); diff --git a/server/spicevmc.cpp b/server/spicevmc.cpp index 0f4ecf9f..3dbc3eaf 100644 --- a/server/spicevmc.cpp +++ b/server/spicevmc.cpp @@ -205,10 +205,9 @@ try_compress_lz4(RedVmcChannel *channel, red::shared_ptr& msg_it return false; } auto msg_item_compressed = red::make_shared(); - compressed_data_count = LZ4_compress_default((char*)&msg_item->buf, - (char*)&msg_item_compressed->buf, - n, - BUF_SIZE); + compressed_data_count = + LZ4_compress_default(reinterpret_cast(&msg_item->buf), + reinterpret_cast(&msg_item_compressed->buf), n, BUF_SIZE); if (compressed_data_count > 0 && compressed_data_count < n) { stat_inc_counter(channel->out_uncompressed, n); @@ -284,7 +283,7 @@ static void spicevmc_port_send_event(RedChannelClient *rcc, uint8_t event) void RedCharDeviceSpiceVmc::remove_client(RedCharDeviceClientOpaque *opaque) { - auto client = (RedClient *) opaque; + auto client = reinterpret_cast(opaque); spice_assert(channel->rcc && channel->rcc->get_client() == client); @@ -305,8 +304,9 @@ void VmcChannelClient::on_disconnect() &channel->recv_from_client_buf); if (channel->chardev) { - if (channel->chardev->client_exists((RedCharDeviceClientOpaque *)client)) { - channel->chardev->client_remove((RedCharDeviceClientOpaque *)client); + auto opaque_client = reinterpret_cast(client); + if (channel->chardev->client_exists(opaque_client)) { + channel->chardev->client_remove(opaque_client); } else { red_channel_warning(channel, "client %p have already been removed from char dev %p", @@ -334,8 +334,8 @@ bool VmcChannelClient::handle_migrate_data(uint32_t size, void *message) channel = get_channel(); - header = (SpiceMigrateDataHeader *)message; - mig_data = (SpiceMigrateDataSpiceVmc *)(header + 1); + header = static_cast(message); + mig_data = reinterpret_cast(header + 1); spice_assert(size >= sizeof(SpiceMigrateDataHeader) + sizeof(SpiceMigrateDataSpiceVmc)); if (!migration_protocol_validate_header(header, @@ -364,10 +364,10 @@ static bool handle_compressed_msg(RedVmcChannel *channel, RedChannelClient *rcc, #ifdef USE_LZ4 case SPICE_DATA_COMPRESSION_TYPE_LZ4: { uint8_t *decompressed = write_buf->buf; - decompressed_size = LZ4_decompress_safe ((char *)compressed_data_msg->compressed_data, - (char *)decompressed, - compressed_data_msg->compressed_size, - compressed_data_msg->uncompressed_size); + decompressed_size = LZ4_decompress_safe( + reinterpret_cast(compressed_data_msg->compressed_data), + reinterpret_cast(decompressed), compressed_data_msg->compressed_size, + compressed_data_msg->uncompressed_size); stat_inc_counter(channel->in_compressed, compressed_data_msg->compressed_size); stat_inc_counter(channel->in_decompressed, decompressed_size); break; @@ -407,7 +407,7 @@ bool VmcChannelClient::handle_message(uint16_t type, uint32_t size, void *msg) channel->recv_from_client_buf = nullptr; break; case SPICE_MSGC_SPICEVMC_COMPRESSED_DATA: - return handle_compressed_msg(channel, this, (SpiceMsgCompressedData*)msg); + return handle_compressed_msg(channel, this, static_cast(msg)); break; case SPICE_MSGC_PORT_EVENT: if (size != sizeof(uint8_t)) { @@ -415,7 +415,7 @@ bool VmcChannelClient::handle_message(uint16_t type, uint32_t size, void *msg) return FALSE; } if (sif->base.minor_version >= 2 && sif->event != nullptr) - sif->event(channel->chardev_sin, *(uint8_t*)msg); + sif->event(channel->chardev_sin, *static_cast(msg)); break; default: return RedChannelClient::handle_message(type, size, msg); @@ -449,7 +449,7 @@ uint8_t *VmcChannelClient::alloc_recv_buf(uint16_t type, uint32_t size) } default: - return (uint8_t*) g_malloc(size); + return static_cast(g_malloc(size)); } } @@ -529,7 +529,7 @@ static void spicevmc_red_channel_send_port_init(RedChannelClient *rcc, SpiceMsgPortInit init; rcc->init_send_data(SPICE_MSG_PORT_INIT); - init.name = (uint8_t *)i->name.get(); + init.name = reinterpret_cast(i->name.get()); init.name_size = strlen(i->name.get()) + 1; init.opened = i->opened; spice_marshall_msg_port_init(m, &init); @@ -603,7 +603,8 @@ void RedVmcChannel::on_connect(RedClient *client, RedStream *stream, int migrati spicevmc_port_send_init(rcc); } - if (!vmc_channel->chardev->client_add((RedCharDeviceClientOpaque *)client, FALSE, 0, ~0, ~0, rcc->is_waiting_for_migrate_data())) { + if (!vmc_channel->chardev->client_add(reinterpret_cast(client), + FALSE, 0, ~0, ~0, rcc->is_waiting_for_migrate_data())) { spice_warning("failed to add client to spicevmc"); rcc->disconnect(); return; diff --git a/server/stream-channel.cpp b/server/stream-channel.cpp index bc270b0c..184b2604 100644 --- a/server/stream-channel.cpp +++ b/server/stream-channel.cpp @@ -270,7 +270,7 @@ bool StreamChannelClient::handle_message(uint16_t type, uint32_t size, void *msg return false; case SPICE_MSGC_DISPLAY_PREFERRED_VIDEO_CODEC_TYPE: return handle_preferred_video_codec_type( - (SpiceMsgcDisplayPreferredVideoCodecType *)msg); + static_cast(msg)); default: return CommonGraphicsChannelClient::handle_message(type, size, msg); } diff --git a/server/tests/test-channel.cpp b/server/tests/test-channel.cpp index af0e1d6d..a3a470dd 100644 --- a/server/tests/test-channel.cpp +++ b/server/tests/test-channel.cpp @@ -74,7 +74,7 @@ RedTestChannel::on_connect(RedClient *client, RedStream *stream, uint8_t * RedTestChannelClient::alloc_recv_buf(uint16_t type, uint32_t size) { - return (uint8_t*) g_malloc(size); + return static_cast(g_malloc(size)); } void @@ -137,7 +137,7 @@ static SpiceTimer *waked_up_timer; // timer waiting we get data again static void timer_wakeup(void *opaque) { - auto core = (SpiceCoreInterface*) opaque; + auto core = static_cast(opaque); // check we are receiving data again size_t got_data = 0; @@ -159,7 +159,7 @@ static void timer_wakeup(void *opaque) // if we arrive here it means we didn't receive too many watch events static void timeout_watch_count(void *opaque) { - auto core = (SpiceCoreInterface*) opaque; + auto core = static_cast(opaque); // get all pending data alarm(1); @@ -220,7 +220,7 @@ static void channel_loop() memset(&caps, 0, sizeof(caps)); uint32_t common_caps = 1 << SPICE_COMMON_CAP_MINI_HEADER; caps.num_common_caps = 1; - caps.common_caps = (uint32_t*) spice_memdup(&common_caps, sizeof(common_caps)); + caps.common_caps = static_cast(spice_memdup(&common_caps, sizeof(common_caps))); RedClient *client = red_client_new(server, FALSE); g_assert_nonnull(client); diff --git a/server/tests/test-display-base.cpp b/server/tests/test-display-base.cpp index fc0c49ee..b220b7fe 100644 --- a/server/tests/test-display-base.cpp +++ b/server/tests/test-display-base.cpp @@ -68,7 +68,7 @@ static void test_spice_destroy_update(SimpleSpiceUpdate *update) return; } if (update->drawable.clip.type != SPICE_CLIP_TYPE_NONE) { - auto ptr = (uint8_t*)(uintptr_t)update->drawable.clip.data; + auto ptr = reinterpret_cast(static_cast(update->drawable.clip.data)); g_free(ptr); } g_free(update->bitmap); @@ -118,13 +118,17 @@ static void regression_test() } argv = g_strsplit("./regression-test.py", " ", -1); - retval = g_spawn_async(nullptr, argv, nullptr, (GSpawnFlags) (G_SPAWN_SEARCH_PATH|G_SPAWN_DO_NOT_REAP_CHILD), - nullptr, nullptr, &pid, &error); + retval = + g_spawn_async(nullptr, argv, nullptr, + static_cast(G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD), + nullptr, nullptr, &pid, &error); g_strfreev(argv); g_assert(retval); GSource *source = g_child_watch_source_new(pid); - g_source_set_callback(source, (GSourceFunc)(void*)child_exited, nullptr, nullptr); + g_source_set_callback(source, + reinterpret_cast(reinterpret_cast(child_exited)), + nullptr, nullptr); guint id = g_source_attach(source, basic_event_loop_get_context()); g_assert(id != 0); g_source_unref(source); @@ -205,7 +209,8 @@ test_spice_create_update_from_bitmap(uint32_t surface_id, } else { QXLClipRects *cmd_clip; - cmd_clip = (QXLClipRects*) g_malloc0(sizeof(QXLClipRects) + num_clip_rects*sizeof(QXLRect)); + cmd_clip = static_cast( + g_malloc0(sizeof(QXLClipRects) + num_clip_rects * sizeof(QXLRect))); cmd_clip->num_rects = num_clip_rects; cmd_clip->chunk.data_size = num_clip_rects*sizeof(QXLRect); cmd_clip->chunk.prev_chunk = cmd_clip->chunk.next_chunk = 0; @@ -255,7 +260,7 @@ static SimpleSpiceUpdate *test_spice_create_update_solid(uint32_t surface_id, QX bw = bbox.right - bbox.left; bh = bbox.bottom - bbox.top; - bitmap = (uint8_t*) g_malloc(bw * bh * 4); + bitmap = static_cast(g_malloc(bw * bh * 4)); dst = SPICE_ALIGNED_CAST(uint32_t *, bitmap); for (i = 0 ; i < bh * bw ; ++i, ++dst) { @@ -290,7 +295,7 @@ static SimpleSpiceUpdate *test_spice_create_update_draw(Test *test, uint32_t sur bw = test->primary_width/SINGLE_PART; bh = 48; - bitmap = dst = (uint8_t*) g_malloc(bw * bh * 4); + bitmap = dst = static_cast(g_malloc(bw * bh * 4)); //printf("allocated %p\n", dst); for (i = 0 ; i < bh * bw ; ++i, dst+=4) { @@ -640,7 +645,7 @@ static int req_cmd_notification(QXLInstance *qin) static void do_wakeup(void *opaque) { - auto test = (Test*) opaque; + auto test = static_cast(opaque); int notify; test->cursor_notify = NOTIFY_CURSOR_BATCH; @@ -657,7 +662,7 @@ static void do_wakeup(void *opaque) static void release_resource(SPICE_GNUC_UNUSED QXLInstance *qin, struct QXLReleaseInfoExt release_info) { - auto ext = (QXLCommandExt*)(uintptr_t)release_info.info->id; + auto ext = reinterpret_cast(static_cast(release_info.info->id)); //printf("%s\n", __func__); spice_assert(release_info.group_id == MEM_SLOT_GROUP_ID); switch (ext->cmd.type) { @@ -668,7 +673,7 @@ static void release_resource(SPICE_GNUC_UNUSED QXLInstance *qin, g_free(ext); break; case QXL_CMD_CURSOR: { - auto cmd = (QXLCursorCmd *)(uintptr_t)ext->cmd.data; + auto cmd = reinterpret_cast(static_cast(ext->cmd.data)); if (cmd->type == QXL_CURSOR_SET || cmd->type == QXL_CURSOR_MOVE) { g_free(cmd); } @@ -874,7 +879,7 @@ void test_add_agent_interface(SpiceServer *server) spice_server_add_interface(server, &vdagent_sin.base); } -void test_set_simple_command_list(Test *test, const int *simple_commands, int num_commands) +void test_set_simple_command_list(Test *test, const CommandType *simple_commands, int num_commands) { int i; @@ -882,7 +887,7 @@ void test_set_simple_command_list(Test *test, const int *simple_commands, int nu test->commands = g_new0(Command, num_commands); test->num_commands = num_commands; for (i = 0 ; i < num_commands; ++i) { - test->commands[i].command = (CommandType) simple_commands[i]; + test->commands[i].command = simple_commands[i]; } } diff --git a/server/tests/test-display-base.h b/server/tests/test-display-base.h index a5e1f1b2..ee58aae2 100644 --- a/server/tests/test-display-base.h +++ b/server/tests/test-display-base.h @@ -131,7 +131,8 @@ struct Test { void (*on_client_disconnected)(Test *test); }; -void test_set_simple_command_list(Test *test, const int *simple_commands, int num_commands); +void test_set_simple_command_list(Test *test, + const CommandType *simple_commands, int num_commands); void test_set_command_list(Test *test, Command *new_commands, int num_commands); void test_add_display_interface(Test *test); void test_add_agent_interface(SpiceServer *server); // TODO - Test *test diff --git a/server/tests/test-display-no-ssl.c b/server/tests/test-display-no-ssl.c index c13f5a5e..4e8c0982 100644 --- a/server/tests/test-display-no-ssl.c +++ b/server/tests/test-display-no-ssl.c @@ -37,7 +37,7 @@ static void pinger(SPICE_GNUC_UNUSED void *opaque) core->timer_start(ping_timer, ping_ms); } -static const int simple_commands[] = { +static const CommandType simple_commands[] = { //SIMPLE_CREATE_SURFACE, //SIMPLE_DRAW, //SIMPLE_DESTROY_SURFACE, diff --git a/server/tests/test-stream-device.cpp b/server/tests/test-stream-device.cpp index 0892a3c9..faed0d1c 100644 --- a/server/tests/test-stream-device.cpp +++ b/server/tests/test-stream-device.cpp @@ -310,7 +310,7 @@ static void test_stream_device_format_after_data(TestFixture *fixture, gconstpoi // check empty message static void test_stream_device_empty(TestFixture *fixture, gconstpointer user_data) { - const auto msg_type = (StreamMsgType) GPOINTER_TO_INT(user_data); + const auto msg_type = static_cast GPOINTER_TO_INT(user_data); uint8_t *p = vmc->message; // add some messages into device buffer @@ -361,7 +361,7 @@ static void test_stream_device_data_message(TestFixture *fixture, gconstpointer p = add_format(p, 640, 480, SPICE_VIDEO_CODEC_TYPE_MJPEG); p = add_stream_hdr(p, STREAM_TYPE_DATA, 1017); for (int i = 0; i < 1017; ++i, ++p) { - *p = (uint8_t) (i * 123 + 57); + *p = static_cast(i * 123 + 57); } vmc_emu_add_read_till(vmc, vmc->message + 51); vmc_emu_add_read_till(vmc, vmc->message + 123); @@ -402,7 +402,7 @@ static void test_display_info(TestFixture *fixture, gconstpointer user_data) p = add_stream_hdr(p, STREAM_TYPE_DEVICE_DISPLAY_INFO, sizeof(info) + sizeof(address)); memcpy(p, &info, sizeof(info)); p += sizeof(info); - strcpy((char*)p, address); + strcpy(reinterpret_cast(p), address); p += sizeof(address); vmc_emu_add_read_till(vmc, p); diff --git a/server/tests/test-two-servers.c b/server/tests/test-two-servers.c index 40a0e571..2437fe44 100644 --- a/server/tests/test-two-servers.c +++ b/server/tests/test-two-servers.c @@ -25,7 +25,7 @@ static SpiceCoreInterface *core; -static const int simple_commands[] = { +static const CommandType simple_commands[] = { //SIMPLE_CREATE_SURFACE, //SIMPLE_DRAW, //SIMPLE_DESTROY_SURFACE, diff --git a/server/tree.cpp b/server/tree.cpp index b95ae602..c8d685fb 100644 --- a/server/tree.cpp +++ b/server/tree.cpp @@ -114,7 +114,7 @@ struct DumpItem { static void dump_item(TreeItem *item, void *data) { - auto di = (DumpItem*) data; + auto di = static_cast(data); const char *item_prefix = "|--"; int i; @@ -246,7 +246,7 @@ void container_cleanup(Container *container) Container *next = container->base.container; if (container->items.next != &container->items) { SPICE_VERIFY(SPICE_OFFSETOF(TreeItem, siblings_link) == 0); - auto item = (TreeItem *)ring_get_head(&container->items); + auto item = reinterpret_cast(ring_get_head(&container->items)); spice_assert(item); ring_remove(&item->siblings_link); ring_add_after(&item->siblings_link, &container->base.siblings_link); @@ -262,7 +262,7 @@ Shadow* tree_item_find_shadow(TreeItem *item) { while (item->type == TREE_ITEM_TYPE_CONTAINER) { SPICE_VERIFY(SPICE_OFFSETOF(TreeItem, siblings_link) == 0); - if (!(item = (TreeItem *)ring_get_tail(&CONTAINER(item)->items))) { + if (!(item = reinterpret_cast(ring_get_tail(&CONTAINER(item)->items)))) { return nullptr; } } diff --git a/server/video-stream.cpp b/server/video-stream.cpp index 4de92b63..056d0c31 100644 --- a/server/video-stream.cpp +++ b/server/video-stream.cpp @@ -168,8 +168,8 @@ VideoStreamClipItem::VideoStreamClipItem(VideoStreamAgent *agent): agent->stream->refs++; int n_rects = pixman_region32_n_rects(&agent->clip); - rects.reset((SpiceClipRects*) g_malloc(sizeof(SpiceClipRects) + - n_rects * sizeof(SpiceRect))); + rects.reset(static_cast( + g_malloc(sizeof(SpiceClipRects) + n_rects * sizeof(SpiceRect)))); rects->num_rects = n_rects; region_ret_rects(&agent->clip, rects->rects, n_rects); } @@ -277,7 +277,8 @@ static void attach_stream(DisplayChannel *display, Drawable *drawable, VideoStre uint64_t duration = drawable->creation_time - stream->input_fps_start_time; if (duration >= RED_STREAM_INPUT_FPS_TIMEOUT) { /* Round to the nearest integer, for instance 24 for 23.976 */ - stream->input_fps = ((uint64_t)stream->num_input_frames * 1000 * 1000 * 1000 + duration / 2) / duration; + stream->input_fps = + (uint64_t{stream->num_input_frames} * 1000 * 1000 * 1000 + duration / 2) / duration; spice_debug("input-fps=%u", stream->input_fps); stream->num_input_frames = 0; stream->input_fps_start_time = drawable->creation_time; @@ -338,7 +339,7 @@ static void before_reattach_stream(DisplayChannel *display, index = display_channel_get_video_stream_id(display, stream); for (dpi_link = stream->current->pipes; dpi_link; dpi_link = dpi_next) { - auto dpi = (RedDrawablePipeItem*) dpi_link->data; + auto dpi = static_cast(dpi_link->data); dpi_next = dpi_link->next; dcc = dpi->dcc; agent = dcc_get_video_stream_agent(dcc, index); @@ -640,7 +641,7 @@ static uint64_t get_initial_bit_rate(DisplayChannelClient *dcc, VideoStream *str static uint32_t get_roundtrip_ms(void *opaque) { - auto agent = (VideoStreamAgent*) opaque; + auto agent = static_cast(opaque); int roundtrip; RedChannelClient *rcc = agent->dcc; @@ -661,14 +662,14 @@ static uint32_t get_roundtrip_ms(void *opaque) static uint32_t get_source_fps(void *opaque) { - auto agent = (VideoStreamAgent*) opaque; + auto agent = static_cast(opaque); return agent->stream->input_fps; } static void update_client_playback_delay(void *opaque, uint32_t delay_ms) { - auto agent = (VideoStreamAgent*) opaque; + auto agent = static_cast(opaque); DisplayChannelClient *dcc = agent->dcc; RedClient *client = dcc->get_client(); RedsState *reds = client->get_server(); @@ -685,13 +686,13 @@ static void update_client_playback_delay(void *opaque, uint32_t delay_ms) static void bitmap_ref(gpointer data) { - auto red_drawable = (RedDrawable*)data; + auto red_drawable = static_cast(data); shared_ptr_add_ref(red_drawable); } static void bitmap_unref(gpointer data) { - auto red_drawable = (RedDrawable*)data; + auto red_drawable = static_cast(data); shared_ptr_unref(red_drawable); } @@ -831,8 +832,8 @@ static void dcc_detach_stream_gracefully(DisplayChannelClient *dcc, rect_debug(&stream->current->red_drawable->bbox); auto upgrade_item = red::make_shared(stream->current); n_rects = pixman_region32_n_rects(&upgrade_item->drawable->tree_item.base.rgn); - upgrade_item->rects.reset((SpiceClipRects*) g_malloc(sizeof(SpiceClipRects) + - n_rects * sizeof(SpiceRect))); + upgrade_item->rects.reset(static_cast( + g_malloc(sizeof(SpiceClipRects) + n_rects * sizeof(SpiceRect)))); upgrade_item->rects->num_rects = n_rects; region_ret_rects(&upgrade_item->drawable->tree_item.base.rgn, upgrade_item->rects->rects, n_rects); -- cgit v1.2.3