aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2022-04-26 09:43:54 +0200
committerSimon Ser <contact@emersion.fr>2022-04-28 10:09:50 +0200
commit6c350799b22ddc5cb89467c95692437bbf0116b9 (patch)
tree4559c68cb117d9c044e79fb0fbb7453042538375
parent54653b5d95935e379e26db5518456a66384b5405 (diff)
Zero-initialize structs in init functions
Ensures there is no field left to its previous undefined value after calling an init function.
-rw-r--r--backend/backend.c2
-rw-r--r--backend/drm/drm.c1
-rw-r--r--render/allocator/allocator.c1
-rw-r--r--render/wlr_renderer.c2
-rw-r--r--render/wlr_texture.c2
-rw-r--r--types/data_device/wlr_data_source.c1
-rw-r--r--types/output/output.c2
-rw-r--r--types/scene/wlr_scene.c2
-rw-r--r--types/wlr_buffer.c2
-rw-r--r--types/wlr_compositor.c2
-rw-r--r--types/wlr_input_device.c1
-rw-r--r--types/wlr_keyboard.c1
-rw-r--r--types/wlr_pointer.c1
-rw-r--r--types/wlr_primary_selection.c1
-rw-r--r--types/wlr_switch.c1
-rw-r--r--types/wlr_tablet_pad.c1
-rw-r--r--types/wlr_tablet_tool.c1
-rw-r--r--types/wlr_touch.c1
-rw-r--r--util/addon.c3
-rw-r--r--xwayland/selection/selection.c2
20 files changed, 29 insertions, 1 deletions
diff --git a/backend/backend.c b/backend/backend.c
index bfb43ba0..ac6e2165 100644
--- a/backend/backend.c
+++ b/backend/backend.c
@@ -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);
diff --git a/backend/drm/drm.c b/backend/drm/drm.c
index 2b573295..5a828426 100644
--- a/backend/drm/drm.c
+++ b/backend/drm/drm.c
@@ -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);
diff --git a/render/allocator/allocator.c b/render/allocator/allocator.c
index 2c75421f..83e836ae 100644
--- a/render/allocator/allocator.c
+++ b/render/allocator/allocator.c
@@ -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);
diff --git a/render/wlr_renderer.c b/render/wlr_renderer.c
index 2b5cf994..478db745 100644
--- a/render/wlr_renderer.c
+++ b/render/wlr_renderer.c
@@ -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);
diff --git a/render/wlr_texture.c b/render/wlr_texture.c
index 2cdf08c5..36cbf136 100644
--- a/render/wlr_texture.c
+++ b/render/wlr_texture.c
@@ -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;
diff --git a/types/data_device/wlr_data_source.c b/types/data_device/wlr_data_source.c
index 1baaac60..b07c4487 100644
--- a/types/data_device/wlr_data_source.c
+++ b/types/data_device/wlr_data_source.c
@@ -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);
diff --git a/types/output/output.c b/types/output/output.c
index e4d45043..68a74b6b 100644
--- a/types/output/output.c
+++ b/types/output/output.c
@@ -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;
diff --git a/types/scene/wlr_scene.c b/types/scene/wlr_scene.c
index 9353fef5..d88dd55f 100644
--- a/types/scene/wlr_scene.c
+++ b/types/scene/wlr_scene.c
@@ -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);
diff --git a/types/wlr_buffer.c b/types/wlr_buffer.c
index 0e091f56..e50fad40 100644
--- a/types/wlr_buffer.c
+++ b/types/wlr_buffer.c
@@ -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;
diff --git a/types/wlr_compositor.c b/types/wlr_compositor.c
index bb4275ef..1e86e9e7 100644
--- a/types/wlr_compositor.c
+++ b/types/wlr_compositor.c
@@ -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;
diff --git a/types/wlr_input_device.c b/types/wlr_input_device.c
index d87935d8..87cc64b8 100644
--- a/types/wlr_input_device.c
+++ b/types/wlr_input_device.c
@@ -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;
diff --git a/types/wlr_keyboard.c b/types/wlr_keyboard.c
index df99e8ba..2a82cfa8 100644
--- a/types/wlr_keyboard.c
+++ b/types/wlr_keyboard.c
@@ -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;
diff --git a/types/wlr_pointer.c b/types/wlr_pointer.c
index 09782cda..e4d39f6a 100644
--- a/types/wlr_pointer.c
+++ b/types/wlr_pointer.c
@@ -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;
diff --git a/types/wlr_primary_selection.c b/types/wlr_primary_selection.c
index 0875462c..21784aae 100644
--- a/types/wlr_primary_selection.c
+++ b/types/wlr_primary_selection.c
@@ -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;
diff --git a/types/wlr_switch.c b/types/wlr_switch.c
index 8e84841d..3b05ec6c 100644
--- a/types/wlr_switch.c
+++ b/types/wlr_switch.c
@@ -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;
diff --git a/types/wlr_tablet_pad.c b/types/wlr_tablet_pad.c
index df389c46..353b4d43 100644
--- a/types/wlr_tablet_pad.c
+++ b/types/wlr_tablet_pad.c
@@ -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;
diff --git a/types/wlr_tablet_tool.c b/types/wlr_tablet_tool.c
index a5c9d44f..7d8eb418 100644
--- a/types/wlr_tablet_tool.c
+++ b/types/wlr_tablet_tool.c
@@ -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;
diff --git a/types/wlr_touch.c b/types/wlr_touch.c
index 96d196d3..28fec198 100644
--- a/types/wlr_touch.c
+++ b/types/wlr_touch.c
@@ -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;
diff --git a/util/addon.c b/util/addon.c
index 395a8df6..c9b373a7 100644
--- a/util/addon.c
+++ b/util/addon.c
@@ -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) {
diff --git a/xwayland/selection/selection.c b/xwayland/selection/selection.c
index 26817fbb..4cc8b627 100644
--- a/xwayland/selection/selection.c
+++ b/xwayland/selection/selection.c
@@ -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);