From 7a9f8d8d6bf72fcea210552b7bec9b99f342f857 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Fri, 7 Jul 2023 14:34:56 +0200 Subject: [PATCH] Use struct initializers instead of memset() This is a bit more type-safe. --- CONTRIBUTING.md | 4 ++-- backend/backend.c | 5 +++-- backend/drm/atomic.c | 2 +- backend/drm/drm.c | 13 +++++++------ backend/drm/renderer.c | 2 +- render/allocator/allocator.c | 7 ++++--- render/drm_format_set.c | 5 +++-- render/gles2/texture.c | 9 +++++---- render/pass.c | 5 +++-- render/swapchain.c | 2 +- render/wlr_renderer.c | 5 +++-- render/wlr_texture.c | 11 ++++++----- types/buffer/buffer.c | 9 +++++---- types/buffer/dmabuf.c | 2 +- types/data_device/wlr_data_source.c | 7 ++++--- types/output/output.c | 18 ++++++++++-------- types/scene/wlr_scene.c | 15 ++++++++------- types/wlr_compositor.c | 8 ++++---- types/wlr_cursor.c | 6 +++--- types/wlr_damage_ring.c | 8 ++++---- types/wlr_input_device.c | 9 ++++----- types/wlr_keyboard.c | 16 ++++++++-------- types/wlr_linux_dmabuf_v1.c | 4 ++-- types/wlr_output_layout.c | 2 +- types/wlr_pointer.c | 5 +++-- types/wlr_presentation_time.c | 15 ++++++++------- types/wlr_primary_selection.c | 5 +++-- types/wlr_switch.c | 5 +++-- types/wlr_tablet_pad.c | 5 +++-- types/wlr_tablet_tool.c | 5 +++-- types/wlr_touch.c | 5 +++-- types/wlr_virtual_pointer_v1.c | 2 +- util/addon.c | 9 +++++---- xwayland/selection/selection.c | 17 +++++++++-------- 34 files changed, 134 insertions(+), 113 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a9b79834..2c234273 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -197,8 +197,8 @@ Functions that are responsible for constructing objects should take one of the two following forms: * `init`: for functions which accept a pointer to a pre-allocated object (e.g. -a member of a struct) and initialize it. Such functions must call `memset()` -to zero out the memory before initializing it to avoid leaving unset fields. +a member of a struct) and initialize it. Such functions must zero out the +memory before initializing it to avoid leaving unset fields. * `create`: for functions which allocate the memory for an object, initialize it, and return a pointer. Such functions should allocate the memory with `calloc()` to avoid leaving unset fields. diff --git a/backend/backend.c b/backend/backend.c index c6afe14b..125ed411 100644 --- a/backend/backend.c +++ b/backend/backend.c @@ -40,8 +40,9 @@ void wlr_backend_init(struct wlr_backend *backend, const struct wlr_backend_impl *impl) { - memset(backend, 0, sizeof(*backend)); - backend->impl = impl; + *backend = (struct wlr_backend){ + .impl = impl, + }; wl_signal_init(&backend->events.destroy); wl_signal_init(&backend->events.new_input); wl_signal_init(&backend->events.new_output); diff --git a/backend/drm/atomic.c b/backend/drm/atomic.c index 7c5fc0ba..c2005f96 100644 --- a/backend/drm/atomic.c +++ b/backend/drm/atomic.c @@ -50,7 +50,7 @@ struct atomic { }; static void atomic_begin(struct atomic *atom) { - memset(atom, 0, sizeof(*atom)); + *atom = (struct atomic){0}; atom->req = drmModeAtomicAlloc(); if (!atom->req) { diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 8c639379..5f71f923 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -445,11 +445,12 @@ static bool drm_crtc_commit(struct wlr_drm_connector *conn, static void drm_connector_state_init(struct wlr_drm_connector_state *state, struct wlr_drm_connector *conn, const struct wlr_output_state *base) { - memset(state, 0, sizeof(*state)); - state->base = base; - state->modeset = base->allow_artifacts; - state->active = (base->committed & WLR_OUTPUT_STATE_ENABLED) ? - base->enabled : conn->output.enabled; + *state = (struct wlr_drm_connector_state){ + .base = base, + .modeset = base->allow_artifacts, + .active = (base->committed & WLR_OUTPUT_STATE_ENABLED) ? + base->enabled : conn->output.enabled, + }; if (base->committed & WLR_OUTPUT_STATE_MODE) { switch (base->mode_type) { @@ -1028,7 +1029,7 @@ static void drm_connector_destroy_output(struct wlr_output *output) { free(mode); } - memset(&conn->output, 0, sizeof(struct wlr_output)); + conn->output = (struct wlr_output){0}; } static const struct wlr_drm_format_set *drm_connector_get_cursor_formats( diff --git a/backend/drm/renderer.c b/backend/drm/renderer.c index 56468960..f98cc869 100644 --- a/backend/drm/renderer.c +++ b/backend/drm/renderer.c @@ -55,7 +55,7 @@ static void finish_drm_surface(struct wlr_drm_surface *surf) { wlr_swapchain_destroy(surf->swapchain); - memset(surf, 0, sizeof(*surf)); + *surf = (struct wlr_drm_surface){0}; } bool init_drm_surface(struct wlr_drm_surface *surf, diff --git a/render/allocator/allocator.c b/render/allocator/allocator.c index 10284cdd..2b7da4f1 100644 --- a/render/allocator/allocator.c +++ b/render/allocator/allocator.c @@ -22,9 +22,10 @@ void wlr_allocator_init(struct wlr_allocator *alloc, const struct wlr_allocator_interface *impl, uint32_t buffer_caps) { assert(impl && impl->destroy && impl->create_buffer); - memset(alloc, 0, sizeof(*alloc)); - alloc->impl = impl; - alloc->buffer_caps = buffer_caps; + *alloc = (struct wlr_allocator){ + .impl = impl, + .buffer_caps = buffer_caps, + }; wl_signal_init(&alloc->events.destroy); } diff --git a/render/drm_format_set.c b/render/drm_format_set.c index b8c33aa6..1b837fa5 100644 --- a/render/drm_format_set.c +++ b/render/drm_format_set.c @@ -86,8 +86,9 @@ bool wlr_drm_format_set_add(struct wlr_drm_format_set *set, uint32_t format, } void wlr_drm_format_init(struct wlr_drm_format *fmt, uint32_t format) { - memset(fmt, 0, sizeof(*fmt)); - fmt->format = format; + *fmt = (struct wlr_drm_format){ + .format = format, + }; } bool wlr_drm_format_has(const struct wlr_drm_format *fmt, uint64_t modifier) { diff --git a/render/gles2/texture.c b/render/gles2/texture.c index 5faa54a2..4f884d73 100644 --- a/render/gles2/texture.c +++ b/render/gles2/texture.c @@ -373,8 +373,9 @@ struct wlr_texture *gles2_texture_from_buffer(struct wlr_renderer *wlr_renderer, void wlr_gles2_texture_get_attribs(struct wlr_texture *wlr_texture, struct wlr_gles2_texture_attribs *attribs) { struct wlr_gles2_texture *texture = gles2_get_texture(wlr_texture); - memset(attribs, 0, sizeof(*attribs)); - attribs->target = texture->target; - attribs->tex = texture->tex; - attribs->has_alpha = texture->has_alpha; + *attribs = (struct wlr_gles2_texture_attribs){ + .target = texture->target, + .tex = texture->tex, + .has_alpha = texture->has_alpha, + }; } diff --git a/render/pass.c b/render/pass.c index c64772db..650353cb 100644 --- a/render/pass.c +++ b/render/pass.c @@ -15,8 +15,9 @@ struct wlr_render_pass_legacy { void wlr_render_pass_init(struct wlr_render_pass *render_pass, const struct wlr_render_pass_impl *impl) { assert(impl->submit && impl->add_texture && impl->add_rect); - memset(render_pass, 0, sizeof(*render_pass)); - render_pass->impl = impl; + *render_pass = (struct wlr_render_pass){ + .impl = impl, + }; } bool wlr_render_pass_submit(struct wlr_render_pass *render_pass) { diff --git a/render/swapchain.c b/render/swapchain.c index f72e722c..a2b6373b 100644 --- a/render/swapchain.c +++ b/render/swapchain.c @@ -42,7 +42,7 @@ static void slot_reset(struct wlr_swapchain_slot *slot) { wl_list_remove(&slot->release.link); } wlr_buffer_drop(slot->buffer); - memset(slot, 0, sizeof(*slot)); + *slot = (struct wlr_swapchain_slot){0}; } void wlr_swapchain_destroy(struct wlr_swapchain *swapchain) { diff --git a/render/wlr_renderer.c b/render/wlr_renderer.c index e8da28fd..d92d1bef 100644 --- a/render/wlr_renderer.c +++ b/render/wlr_renderer.c @@ -44,8 +44,9 @@ void wlr_renderer_init(struct wlr_renderer *renderer, assert(impl->get_shm_texture_formats); assert(impl->get_render_buffer_caps); - memset(renderer, 0, sizeof(*renderer)); - renderer->impl = impl; + *renderer = (struct wlr_renderer){ + .impl = impl, + }; wl_signal_init(&renderer->events.destroy); wl_signal_init(&renderer->events.lost); diff --git a/render/wlr_texture.c b/render/wlr_texture.c index e327bb5c..8c003cfb 100644 --- a/render/wlr_texture.c +++ b/render/wlr_texture.c @@ -10,11 +10,12 @@ void wlr_texture_init(struct wlr_texture *texture, struct wlr_renderer *renderer const struct wlr_texture_impl *impl, uint32_t width, uint32_t height) { assert(renderer); - memset(texture, 0, sizeof(*texture)); - texture->renderer = renderer; - texture->impl = impl; - texture->width = width; - texture->height = height; + *texture = (struct wlr_texture){ + .renderer = renderer, + .impl = impl, + .width = width, + .height = height, + }; } void wlr_texture_destroy(struct wlr_texture *texture) { diff --git a/types/buffer/buffer.c b/types/buffer/buffer.c index 28370aef..a8e9c54d 100644 --- a/types/buffer/buffer.c +++ b/types/buffer/buffer.c @@ -11,10 +11,11 @@ void wlr_buffer_init(struct wlr_buffer *buffer, assert(impl->begin_data_ptr_access && impl->end_data_ptr_access); } - memset(buffer, 0, sizeof(*buffer)); - buffer->impl = impl; - buffer->width = width; - buffer->height = height; + *buffer = (struct wlr_buffer){ + .impl = impl, + .width = width, + .height = height, + }; wl_signal_init(&buffer->events.destroy); wl_signal_init(&buffer->events.release); wlr_addon_set_init(&buffer->addons); diff --git a/types/buffer/dmabuf.c b/types/buffer/dmabuf.c index b8340ac9..5ceb5172 100644 --- a/types/buffer/dmabuf.c +++ b/types/buffer/dmabuf.c @@ -57,7 +57,7 @@ bool dmabuf_buffer_drop(struct wlr_dmabuf_buffer *buffer) { if (!wlr_dmabuf_attributes_copy(&saved_dmabuf, &buffer->dmabuf)) { wlr_log(WLR_ERROR, "Failed to save DMA-BUF"); ok = false; - memset(&buffer->dmabuf, 0, sizeof(buffer->dmabuf)); + buffer->dmabuf = (struct wlr_dmabuf_attributes){0}; } else { buffer->dmabuf = saved_dmabuf; buffer->saved = true; diff --git a/types/data_device/wlr_data_source.c b/types/data_device/wlr_data_source.c index dc9725fb..acd2b707 100644 --- a/types/data_device/wlr_data_source.c +++ b/types/data_device/wlr_data_source.c @@ -14,11 +14,12 @@ void wlr_data_source_init(struct wlr_data_source *source, const struct wlr_data_source_impl *impl) { assert(impl->send); - memset(source, 0, sizeof(*source)); - source->impl = impl; + *source = (struct wlr_data_source){ + .impl = impl, + .actions = -1, + }; wl_array_init(&source->mime_types); wl_signal_init(&source->events.destroy); - source->actions = -1; } void wlr_data_source_send(struct wlr_data_source *source, const char *mime_type, diff --git a/types/output/output.c b/types/output/output.c index 4bd2f243..ec00d85b 100644 --- a/types/output/output.c +++ b/types/output/output.c @@ -332,15 +332,17 @@ void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend, assert(impl->set_cursor && impl->move_cursor); } - memset(output, 0, sizeof(*output)); - output->backend = backend; - output->impl = impl; - output->display = display; + *output = (struct wlr_output){ + .backend = backend, + .impl = impl, + .display = display, + .render_format = DRM_FORMAT_XRGB8888, + .transform = WL_OUTPUT_TRANSFORM_NORMAL, + .scale = 1, + .commit_seq = 0, + }; + wl_list_init(&output->modes); - output->render_format = DRM_FORMAT_XRGB8888; - output->transform = WL_OUTPUT_TRANSFORM_NORMAL; - output->scale = 1; - output->commit_seq = 0; wl_list_init(&output->cursors); wl_list_init(&output->layers); wl_list_init(&output->resources); diff --git a/types/scene/wlr_scene.c b/types/scene/wlr_scene.c index d8987fca..3f901669 100644 --- a/types/scene/wlr_scene.c +++ b/types/scene/wlr_scene.c @@ -57,10 +57,11 @@ struct wlr_scene *scene_node_get_root(struct wlr_scene_node *node) { static void scene_node_init(struct wlr_scene_node *node, enum wlr_scene_node_type type, struct wlr_scene_tree *parent) { - memset(node, 0, sizeof(*node)); - node->type = type; - node->parent = parent; - node->enabled = true; + *node = (struct wlr_scene_node){ + .type = type, + .parent = parent, + .enabled = true, + }; wl_list_init(&node->link); @@ -141,7 +142,7 @@ void wlr_scene_node_destroy(struct wlr_scene_node *node) { static void scene_tree_init(struct wlr_scene_tree *tree, struct wlr_scene_tree *parent) { - memset(tree, 0, sizeof(*tree)); + *tree = (struct wlr_scene_tree){0}; scene_node_init(&tree->node, WLR_SCENE_NODE_TREE, parent); wl_list_init(&tree->children); } @@ -386,8 +387,8 @@ static void update_node_update_outputs(struct wlr_scene_node *node, } if (old_primary_output != scene_buffer->primary_output) { - memset(&scene_buffer->prev_feedback_options, 0, - sizeof(scene_buffer->prev_feedback_options)); + scene_buffer->prev_feedback_options = + (struct wlr_linux_dmabuf_feedback_v1_init_options){0}; } uint64_t old_active = scene_buffer->active_outputs; diff --git a/types/wlr_compositor.c b/types/wlr_compositor.c index 80c0495b..bf61f74a 100644 --- a/types/wlr_compositor.c +++ b/types/wlr_compositor.c @@ -588,10 +588,10 @@ struct wlr_surface *wlr_surface_from_resource(struct wl_resource *resource) { } static void surface_state_init(struct wlr_surface_state *state) { - memset(state, 0, sizeof(*state)); - - state->scale = 1; - state->transform = WL_OUTPUT_TRANSFORM_NORMAL; + *state = (struct wlr_surface_state){ + .scale = 1, + .transform = WL_OUTPUT_TRANSFORM_NORMAL, + }; wl_list_init(&state->subsurfaces_above); wl_list_init(&state->subsurfaces_below); diff --git a/types/wlr_cursor.c b/types/wlr_cursor.c index f207c1ea..f2e5c19d 100644 --- a/types/wlr_cursor.c +++ b/types/wlr_cursor.c @@ -302,7 +302,7 @@ static void get_mapping(struct wlr_cursor *cur, struct wlr_input_device *dev, struct wlr_box *box) { assert(cur->state->layout); - memset(box, 0, sizeof(*box)); + *box = (struct wlr_box){0}; struct wlr_cursor_device *c_device = get_cursor_device(cur, dev); if (c_device) { @@ -1146,7 +1146,7 @@ void wlr_cursor_map_input_to_output(struct wlr_cursor *cur, void wlr_cursor_map_to_region(struct wlr_cursor *cur, const struct wlr_box *box) { - memset(&cur->state->mapped_box, 0, sizeof(cur->state->mapped_box)); + cur->state->mapped_box = (struct wlr_box){0}; if (box) { if (wlr_box_empty(box)) { @@ -1159,7 +1159,7 @@ void wlr_cursor_map_to_region(struct wlr_cursor *cur, void wlr_cursor_map_input_to_region(struct wlr_cursor *cur, struct wlr_input_device *dev, const struct wlr_box *box) { - memset(&cur->state->mapped_box, 0, sizeof(cur->state->mapped_box)); + cur->state->mapped_box = (struct wlr_box){0}; struct wlr_cursor_device *c_device = get_cursor_device(cur, dev); if (!c_device) { diff --git a/types/wlr_damage_ring.c b/types/wlr_damage_ring.c index ba270e69..439cceb4 100644 --- a/types/wlr_damage_ring.c +++ b/types/wlr_damage_ring.c @@ -8,10 +8,10 @@ #define WLR_DAMAGE_RING_MAX_RECTS 20 void wlr_damage_ring_init(struct wlr_damage_ring *ring) { - memset(ring, 0, sizeof(*ring)); - - ring->width = INT_MAX; - ring->height = INT_MAX; + *ring = (struct wlr_damage_ring){ + .width = INT_MAX, + .height = INT_MAX, + }; pixman_region32_init(&ring->current); for (size_t i = 0; i < WLR_DAMAGE_RING_PREVIOUS_LEN; ++i) { diff --git a/types/wlr_input_device.c b/types/wlr_input_device.c index 21916d69..7de98b75 100644 --- a/types/wlr_input_device.c +++ b/types/wlr_input_device.c @@ -6,11 +6,10 @@ void wlr_input_device_init(struct wlr_input_device *dev, enum wlr_input_device_type type, const char *name) { - memset(dev, 0, sizeof(*dev)); - dev->type = type; - dev->name = strdup(name); - dev->vendor = 0; - dev->product = 0; + *dev = (struct wlr_input_device){ + .type = type, + .name = strdup(name), + }; wl_signal_init(&dev->events.destroy); } diff --git a/types/wlr_keyboard.c b/types/wlr_keyboard.c index 81181704..6aea09db 100644 --- a/types/wlr_keyboard.c +++ b/types/wlr_keyboard.c @@ -121,20 +121,20 @@ void wlr_keyboard_notify_key(struct wlr_keyboard *keyboard, void wlr_keyboard_init(struct wlr_keyboard *kb, const struct wlr_keyboard_impl *impl, const char *name) { - memset(kb, 0, sizeof(*kb)); + *kb = (struct wlr_keyboard){ + .impl = impl, + .keymap_fd = -1, + + // Sane defaults + .repeat_info.rate = 25, + .repeat_info.delay = 600, + }; wlr_input_device_init(&kb->base, WLR_INPUT_DEVICE_KEYBOARD, name); - kb->impl = impl; wl_signal_init(&kb->events.key); wl_signal_init(&kb->events.modifiers); wl_signal_init(&kb->events.keymap); wl_signal_init(&kb->events.repeat_info); - - kb->keymap_fd = -1; - - // Sane defaults - kb->repeat_info.rate = 25; - kb->repeat_info.delay = 600; } static void keyboard_unset_keymap(struct wlr_keyboard *kb) { diff --git a/types/wlr_linux_dmabuf_v1.c b/types/wlr_linux_dmabuf_v1.c index 7145b980..767c481f 100644 --- a/types/wlr_linux_dmabuf_v1.c +++ b/types/wlr_linux_dmabuf_v1.c @@ -1025,7 +1025,7 @@ struct wlr_linux_dmabuf_feedback_v1_tranche *wlr_linux_dmabuf_feedback_add_tranc wlr_log_errno(WLR_ERROR, "Allocation failed"); return NULL; } - memset(tranche, 0, sizeof(*tranche)); + *tranche = (struct wlr_linux_dmabuf_feedback_v1_tranche){0}; return tranche; } @@ -1053,7 +1053,7 @@ bool wlr_linux_dmabuf_feedback_v1_init_with_options(struct wlr_linux_dmabuf_feed assert(options->scanout_primary_output == NULL || options->output_layer_feedback_event == NULL); - memset(feedback, 0, sizeof(*feedback)); + *feedback = (struct wlr_linux_dmabuf_feedback_v1){0}; int renderer_drm_fd = wlr_renderer_get_drm_fd(options->main_renderer); if (renderer_drm_fd < 0) { diff --git a/types/wlr_output_layout.c b/types/wlr_output_layout.c index 974e6a74..221c8071 100644 --- a/types/wlr_output_layout.c +++ b/types/wlr_output_layout.c @@ -339,7 +339,7 @@ void wlr_output_layout_closest_point(struct wlr_output_layout *layout, void wlr_output_layout_get_box(struct wlr_output_layout *layout, struct wlr_output *reference, struct wlr_box *dest_box) { - memset(dest_box, 0, sizeof(*dest_box)); + *dest_box = (struct wlr_box){0}; struct wlr_output_layout_output *l_output; if (reference) { diff --git a/types/wlr_pointer.c b/types/wlr_pointer.c index be505b6c..150b9013 100644 --- a/types/wlr_pointer.c +++ b/types/wlr_pointer.c @@ -15,10 +15,11 @@ struct wlr_pointer *wlr_pointer_from_input_device( void wlr_pointer_init(struct wlr_pointer *pointer, const struct wlr_pointer_impl *impl, const char *name) { - memset(pointer, 0, sizeof(*pointer)); + *pointer = (struct wlr_pointer){ + .impl = impl, + }; wlr_input_device_init(&pointer->base, WLR_INPUT_DEVICE_POINTER, name); - pointer->impl = impl; wl_signal_init(&pointer->events.motion); wl_signal_init(&pointer->events.motion_absolute); wl_signal_init(&pointer->events.button); diff --git a/types/wlr_presentation_time.c b/types/wlr_presentation_time.c index 20165276..2a6610f4 100644 --- a/types/wlr_presentation_time.c +++ b/types/wlr_presentation_time.c @@ -249,13 +249,14 @@ void wlr_presentation_feedback_destroy( void wlr_presentation_event_from_output(struct wlr_presentation_event *event, const struct wlr_output_event_present *output_event) { - memset(event, 0, sizeof(*event)); - event->output = output_event->output; - event->tv_sec = (uint64_t)output_event->when->tv_sec; - event->tv_nsec = (uint32_t)output_event->when->tv_nsec; - event->refresh = (uint32_t)output_event->refresh; - event->seq = (uint64_t)output_event->seq; - event->flags = output_event->flags; + *event = (struct wlr_presentation_event){ + .output = output_event->output, + .tv_sec = (uint64_t)output_event->when->tv_sec, + .tv_nsec = (uint32_t)output_event->when->tv_nsec, + .refresh = (uint32_t)output_event->refresh, + .seq = (uint64_t)output_event->seq, + .flags = output_event->flags, + }; } static void feedback_unset_output(struct wlr_presentation_feedback *feedback) { diff --git a/types/wlr_primary_selection.c b/types/wlr_primary_selection.c index d576bf0a..e3212d6f 100644 --- a/types/wlr_primary_selection.c +++ b/types/wlr_primary_selection.c @@ -7,10 +7,11 @@ void wlr_primary_selection_source_init( struct wlr_primary_selection_source *source, const struct wlr_primary_selection_source_impl *impl) { assert(impl->send); - memset(source, 0, sizeof(*source)); + *source = (struct wlr_primary_selection_source){ + .impl = impl, + }; wl_array_init(&source->mime_types); wl_signal_init(&source->events.destroy); - source->impl = impl; } void wlr_primary_selection_source_destroy( diff --git a/types/wlr_switch.c b/types/wlr_switch.c index 5a2083ff..93033aab 100644 --- a/types/wlr_switch.c +++ b/types/wlr_switch.c @@ -15,10 +15,11 @@ struct wlr_switch *wlr_switch_from_input_device( void wlr_switch_init(struct wlr_switch *switch_device, const struct wlr_switch_impl *impl, const char *name) { - memset(switch_device, 0, sizeof(*switch_device)); + *switch_device = (struct wlr_switch){ + .impl = impl, + }; wlr_input_device_init(&switch_device->base, WLR_INPUT_DEVICE_SWITCH, name); - switch_device->impl = impl; wl_signal_init(&switch_device->events.toggle); } diff --git a/types/wlr_tablet_pad.c b/types/wlr_tablet_pad.c index 34c81301..2c4c04ac 100644 --- a/types/wlr_tablet_pad.c +++ b/types/wlr_tablet_pad.c @@ -16,10 +16,11 @@ struct wlr_tablet_pad *wlr_tablet_pad_from_input_device( void wlr_tablet_pad_init(struct wlr_tablet_pad *pad, const struct wlr_tablet_pad_impl *impl, const char *name) { - memset(pad, 0, sizeof(*pad)); + *pad = (struct wlr_tablet_pad){ + .impl = impl, + }; wlr_input_device_init(&pad->base, WLR_INPUT_DEVICE_TABLET_PAD, name); - pad->impl = impl; wl_signal_init(&pad->events.button); wl_signal_init(&pad->events.ring); wl_signal_init(&pad->events.strip); diff --git a/types/wlr_tablet_tool.c b/types/wlr_tablet_tool.c index a25b71a6..fbab01e3 100644 --- a/types/wlr_tablet_tool.c +++ b/types/wlr_tablet_tool.c @@ -15,10 +15,11 @@ struct wlr_tablet *wlr_tablet_from_input_device( void wlr_tablet_init(struct wlr_tablet *tablet, const struct wlr_tablet_impl *impl, const char *name) { - memset(tablet, 0, sizeof(*tablet)); + *tablet = (struct wlr_tablet){ + .impl = impl, + }; wlr_input_device_init(&tablet->base, WLR_INPUT_DEVICE_TABLET_TOOL, name); - tablet->impl = impl; wl_signal_init(&tablet->events.axis); wl_signal_init(&tablet->events.proximity); wl_signal_init(&tablet->events.tip); diff --git a/types/wlr_touch.c b/types/wlr_touch.c index d6285180..66b35e54 100644 --- a/types/wlr_touch.c +++ b/types/wlr_touch.c @@ -15,10 +15,11 @@ struct wlr_touch *wlr_touch_from_input_device( void wlr_touch_init(struct wlr_touch *touch, const struct wlr_touch_impl *impl, const char *name) { - memset(touch, 0, sizeof(*touch)); + *touch = (struct wlr_touch){ + .impl = impl, + }; wlr_input_device_init(&touch->base, WLR_INPUT_DEVICE_TOUCH, name); - touch->impl = impl; wl_signal_init(&touch->events.down); wl_signal_init(&touch->events.up); wl_signal_init(&touch->events.motion); diff --git a/types/wlr_virtual_pointer_v1.c b/types/wlr_virtual_pointer_v1.c index 44cd21ce..dada46a5 100644 --- a/types/wlr_virtual_pointer_v1.c +++ b/types/wlr_virtual_pointer_v1.c @@ -113,7 +113,7 @@ static void virtual_pointer_frame(struct wl_client *client, /* Deliver pending axis event */ wl_signal_emit_mutable(&pointer->pointer.events.axis, &pointer->axis_event[i]); - memset(&pointer->axis_event[i], 0, sizeof(pointer->axis_event[i])); + pointer->axis_event[i] = (struct wlr_pointer_axis_event){0}; pointer->axis_valid[i] = false; } } diff --git a/util/addon.c b/util/addon.c index 75466691..0f9037a2 100644 --- a/util/addon.c +++ b/util/addon.c @@ -6,7 +6,7 @@ #include void wlr_addon_set_init(struct wlr_addon_set *set) { - memset(set, 0, sizeof(*set)); + *set = (struct wlr_addon_set){0}; wl_list_init(&set->addons); } @@ -26,7 +26,10 @@ void wlr_addon_set_finish(struct wlr_addon_set *set) { void wlr_addon_init(struct wlr_addon *addon, struct wlr_addon_set *set, const void *owner, const struct wlr_addon_interface *impl) { assert(impl); - memset(addon, 0, sizeof(*addon)); + *addon = (struct wlr_addon){ + .impl = impl, + .owner = owner, + }; struct wlr_addon *iter; wl_list_for_each(iter, &set->addons, link) { if (iter->owner == addon->owner && iter->impl == addon->impl) { @@ -34,8 +37,6 @@ void wlr_addon_init(struct wlr_addon *addon, struct wlr_addon_set *set, } } wl_list_insert(&set->addons, &addon->link); - addon->owner = owner; - addon->impl = impl; } void wlr_addon_finish(struct wlr_addon *addon) { diff --git a/xwayland/selection/selection.c b/xwayland/selection/selection.c index 4cc8b627..0079df2f 100644 --- a/xwayland/selection/selection.c +++ b/xwayland/selection/selection.c @@ -34,9 +34,10 @@ void xwm_selection_transfer_destroy_property_reply( void xwm_selection_transfer_init(struct wlr_xwm_selection_transfer *transfer, struct wlr_xwm_selection *selection) { - memset(transfer, 0, sizeof(*transfer)); - transfer->selection = selection; - transfer->wl_client_fd = -1; + *transfer = (struct wlr_xwm_selection_transfer){ + .selection = selection, + .wl_client_fd = -1, + }; } void xwm_selection_transfer_destroy( @@ -175,14 +176,14 @@ int xwm_handle_selection_event(struct wlr_xwm *xwm, void xwm_selection_init(struct wlr_xwm_selection *selection, struct wlr_xwm *xwm, xcb_atom_t atom) { - memset(selection, 0, sizeof(*selection)); + *selection = (struct wlr_xwm_selection){ + .xwm = xwm, + .atom = atom, + .window = xcb_generate_id(xwm->xcb_conn), + }; wl_list_init(&selection->incoming); wl_list_init(&selection->outgoing); - selection->xwm = xwm; - selection->atom = atom; - selection->window = xcb_generate_id(xwm->xcb_conn); - if (atom == xwm->atoms[DND_SELECTION]) { xcb_create_window( xwm->xcb_conn,