Zero-initialize structs in init functions

Ensures there is no field left to its previous undefined value after
calling an init function.
This commit is contained in:
Simon Ser 2022-04-26 09:43:54 +02:00
parent 54653b5d95
commit 6c350799b2
20 changed files with 29 additions and 1 deletions

View File

@ -36,7 +36,7 @@
void wlr_backend_init(struct wlr_backend *backend,
const struct wlr_backend_impl *impl) {
assert(backend);
memset(backend, 0, sizeof(*backend));
backend->impl = impl;
wl_signal_init(&backend->events.destroy);
wl_signal_init(&backend->events.new_input);

View File

@ -380,6 +380,7 @@ static bool drm_crtc_page_flip(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->committed &
(WLR_OUTPUT_STATE_ENABLED | WLR_OUTPUT_STATE_MODE);

View File

@ -18,6 +18,7 @@
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;
wl_signal_init(&alloc->events.destroy);

View File

@ -39,6 +39,8 @@ void wlr_renderer_init(struct wlr_renderer *renderer,
assert(impl->render_quad_with_matrix);
assert(impl->get_shm_texture_formats);
assert(impl->get_render_buffer_caps);
memset(renderer, 0, sizeof(*renderer));
renderer->impl = impl;
wl_signal_init(&renderer->events.destroy);

View File

@ -1,12 +1,14 @@
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <wlr/render/interface.h>
#include <wlr/render/wlr_texture.h>
#include "types/wlr_buffer.h"
void wlr_texture_init(struct wlr_texture *texture,
const struct wlr_texture_impl *impl, uint32_t width, uint32_t height) {
memset(texture, 0, sizeof(*texture));
texture->impl = impl;
texture->width = width;
texture->height = height;

View File

@ -15,6 +15,7 @@ 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;
wl_array_init(&source->mime_types);
wl_signal_init(&source->events.destroy);

View File

@ -377,6 +377,8 @@ void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend,
if (impl->set_cursor || impl->move_cursor) {
assert(impl->set_cursor && impl->move_cursor);
}
memset(output, 0, sizeof(*output));
output->backend = backend;
output->impl = impl;
output->display = display;

View File

@ -48,6 +48,7 @@ static struct wlr_scene *scene_node_get_root(struct wlr_scene_node *node) {
}
static void scene_node_state_init(struct wlr_scene_node_state *state) {
memset(state, 0, sizeof(*state));
wl_list_init(&state->children);
wl_list_init(&state->link);
state->enabled = true;
@ -61,6 +62,7 @@ static void scene_node_init(struct wlr_scene_node *node,
enum wlr_scene_node_type type, struct wlr_scene_node *parent) {
assert(type == WLR_SCENE_NODE_ROOT || parent != NULL);
memset(node, 0, sizeof(*node));
node->type = type;
node->parent = parent;
scene_node_state_init(&node->state);

View File

@ -17,6 +17,8 @@ void wlr_buffer_init(struct wlr_buffer *buffer,
if (impl->begin_data_ptr_access || impl->end_data_ptr_access) {
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;

View File

@ -583,6 +583,8 @@ 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;

View File

@ -7,6 +7,7 @@
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;

View File

@ -116,6 +116,7 @@ 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));
wlr_input_device_init(&kb->base, WLR_INPUT_DEVICE_KEYBOARD, name);
kb->base.keyboard = kb;

View File

@ -8,6 +8,7 @@
void wlr_pointer_init(struct wlr_pointer *pointer,
const struct wlr_pointer_impl *impl, const char *name) {
memset(pointer, 0, sizeof(*pointer));
wlr_input_device_init(&pointer->base, WLR_INPUT_DEVICE_POINTER, name);
pointer->base.pointer = pointer;

View File

@ -8,6 +8,7 @@ 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));
wl_array_init(&source->mime_types);
wl_signal_init(&source->events.destroy);
source->impl = impl;

View File

@ -8,6 +8,7 @@
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));
wlr_input_device_init(&switch_device->base, WLR_INPUT_DEVICE_SWITCH, name);
switch_device->base.switch_device = switch_device;

View File

@ -9,6 +9,7 @@
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));
wlr_input_device_init(&pad->base, WLR_INPUT_DEVICE_TABLET_PAD, name);
pad->base.tablet_pad = pad;

View File

@ -8,6 +8,7 @@
void wlr_tablet_init(struct wlr_tablet *tablet,
const struct wlr_tablet_impl *impl, const char *name) {
memset(tablet, 0, sizeof(*tablet));
wlr_input_device_init(&tablet->base, WLR_INPUT_DEVICE_TABLET_TOOL, name);
tablet->base.tablet = tablet;

View File

@ -8,6 +8,7 @@
void wlr_touch_init(struct wlr_touch *touch,
const struct wlr_touch_impl *impl, const char *name) {
memset(touch, 0, sizeof(*touch));
wlr_input_device_init(&touch->base, WLR_INPUT_DEVICE_TOUCH, name);
touch->base.touch = touch;

View File

@ -1,9 +1,11 @@
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <wayland-server-core.h>
#include <wlr/util/addon.h>
void wlr_addon_set_init(struct wlr_addon_set *set) {
memset(set, 0, sizeof(*set));
wl_list_init(&set->addons);
}
@ -18,6 +20,7 @@ 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(owner && impl);
memset(addon, 0, sizeof(*addon));
struct wlr_addon *iter;
wl_list_for_each(iter, &set->addons, link) {
if (iter->owner == addon->owner && iter->impl == addon->impl) {

View File

@ -34,6 +34,7 @@ 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;
}
@ -174,6 +175,7 @@ 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));
wl_list_init(&selection->incoming);
wl_list_init(&selection->outgoing);