Merge branch 'fanalyzer-fix' into 'master'

GCC static analyzer misc fixes

See merge request wlroots/wlroots!4637
This commit is contained in:
Simon Zeni 2024-06-12 17:33:31 +00:00
commit 52730a2f1e
17 changed files with 57 additions and 6 deletions

View file

@ -260,6 +260,8 @@ static struct wlr_backend *attempt_drm_backend(struct wlr_backend *backend, stru
for (size_t i = 0; i < (size_t)num_gpus; ++i) {
struct wlr_backend *drm = wlr_drm_backend_create(session, gpus[i], primary_drm);
if (!drm) {
wlr_session_close_file(session, gpus[i]);
wlr_log(WLR_ERROR, "Failed to create DRM backend");
continue;
}
@ -270,6 +272,7 @@ static struct wlr_backend *attempt_drm_backend(struct wlr_backend *backend, stru
wlr_multi_backend_add(backend, drm);
}
if (!primary_drm) {
wlr_log(WLR_ERROR, "Could not successfully create backend on any GPU");
return NULL;

View file

@ -40,6 +40,7 @@ static void add_pad_group_from_libinput(struct wlr_tablet_pad *pad,
size_t ring = 0;
for (size_t i = 0; i < pad->ring_count; ++i) {
if (libinput_tablet_pad_mode_group_has_ring(li_group, i)) {
assert(ring < group->ring_count);
group->rings[ring++] = i;
}
}
@ -53,9 +54,11 @@ static void add_pad_group_from_libinput(struct wlr_tablet_pad *pad,
if (group->strips == NULL) {
goto group_fail;
}
size_t strip = 0;
for (size_t i = 0; i < pad->strip_count; ++i) {
if (libinput_tablet_pad_mode_group_has_strip(li_group, i)) {
assert(strip < group->strip_count);
group->strips[strip++] = i;
}
}
@ -69,9 +72,11 @@ static void add_pad_group_from_libinput(struct wlr_tablet_pad *pad,
if (group->buttons == NULL) {
goto group_fail;
}
size_t button = 0;
for (size_t i = 0; i < pad->button_count; ++i) {
if (libinput_tablet_pad_mode_group_has_button(li_group, i)) {
assert(button < group->button_count);
group->buttons[button++] = i;
}
}

View file

@ -402,11 +402,11 @@ static ssize_t explicit_find_gpus(struct wlr_session *session,
break;
}
ret[i] = session_open_if_kms(session, ptr);
if (!ret[i]) {
wlr_log(WLR_ERROR, "Unable to open %s as DRM device", ptr);
struct wlr_device *dev = session_open_if_kms(session, ptr);
if (dev) {
ret[i++] = dev;
} else {
++i;
wlr_log(WLR_ERROR, "Unable to open %s as DRM device", ptr);
}
} while ((ptr = strtok_r(NULL, ":", &save)));

View file

@ -184,7 +184,7 @@ static void handle_tablet_pad_group_buttons(void *data,
struct tablet_pad_group *group = data;
free(group->group.buttons);
group->group.buttons = calloc(1, buttons->size);
group->group.buttons = malloc(buttons->size);
if (!group->group.buttons) {
// FIXME: Add actual error handling
return;

View file

@ -1,4 +1,4 @@
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include <time.h>
@ -101,6 +101,7 @@ static void server_handle_new_output(struct wl_listener *listener, void *data) {
wlr_output_init_render(wlr_output, server->allocator, server->renderer);
struct output *output = calloc(1, sizeof(*output));
assert(output);
output->wlr = wlr_output;
output->server = server;
output->frame.notify = output_handle_frame;

View file

@ -1,3 +1,4 @@
#include <assert.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <GLES2/gl2.h>
@ -145,6 +146,7 @@ static void handle_new_surface(struct wl_listener *listener, void *data) {
struct wlr_surface *wlr_surface = data;
struct surface *surface = calloc(1, sizeof(*surface));
assert(surface);
surface->wlr = wlr_surface;
surface->commit.notify = surface_handle_commit;

View file

@ -1,3 +1,4 @@
#include <assert.h>
#include <getopt.h>
#include <stdbool.h>
#include <stdio.h>
@ -154,6 +155,7 @@ static void server_handle_new_output(struct wl_listener *listener, void *data) {
wlr_output_init_render(wlr_output, server->allocator, server->renderer);
struct fullscreen_output *output = calloc(1, sizeof(*output));
assert(output);
output->wlr_output = wlr_output;
output->server = server;
output->frame.notify = output_handle_frame;

View file

@ -1,3 +1,4 @@
#include <assert.h>
#include <getopt.h>
#include <stdbool.h>
#include <stdio.h>
@ -166,6 +167,7 @@ static void server_handle_new_output(struct wl_listener *listener, void *data) {
wlr_output_init_render(wlr_output, server->allocator, server->renderer);
struct output *output = calloc(1, sizeof(*output));
assert(output);
output->wlr_output = wlr_output;
output->server = server;
wl_list_init(&output->surfaces);
@ -247,6 +249,7 @@ static void server_handle_new_surface(struct wl_listener *listener,
struct output *output;
wl_list_for_each(output, &server->outputs, link) {
struct output_surface *output_surface = calloc(1, sizeof(*output_surface));
assert(output_surface);
output_surface->wlr_surface = wlr_surface;
output_surface->server = server;
output_surface->destroy.notify = output_surface_handle_destroy;

View file

@ -1,3 +1,4 @@
#include <assert.h>
#include <drm_fourcc.h>
#include <limits.h>
#include <math.h>
@ -167,6 +168,7 @@ static void new_output_notify(struct wl_listener *listener, void *data) {
wlr_output_init_render(output, sample->allocator, sample->renderer);
struct sample_output *sample_output = calloc(1, sizeof(*sample_output));
assert(sample_output);
wlr_output_layout_add_auto(sample->layout, output);
sample_output->output = output;
sample_output->sample = sample;
@ -235,7 +237,9 @@ static void new_input_notify(struct wl_listener *listener, void *data) {
switch (device->type) {
case WLR_INPUT_DEVICE_KEYBOARD:;
struct sample_keyboard *keyboard = calloc(1, sizeof(*keyboard));
assert(keyboard);
keyboard->wlr_keyboard = wlr_keyboard_from_input_device(device);
assert(keyboard->wlr_keyboard);
keyboard->sample = sample;
wl_signal_add(&device->events.destroy, &keyboard->destroy);
keyboard->destroy.notify = keyboard_destroy_notify;

View file

@ -193,6 +193,7 @@ static void handle_touch_down(struct wl_listener *listener, void *data) {
struct sample_state *sample = wl_container_of(listener, sample, touch_down);
struct wlr_touch_down_event *event = data;
struct touch_point *point = calloc(1, sizeof(*point));
assert(point);
point->touch_id = event->touch_id;
point->x = event->x;
point->y = event->y;
@ -265,6 +266,7 @@ static void new_output_notify(struct wl_listener *listener, void *data) {
wlr_output_init_render(output, sample->allocator, sample->renderer);
struct sample_output *sample_output = calloc(1, sizeof(*sample_output));
assert(sample_output);
sample_output->output = output;
sample_output->state = sample;
wl_signal_add(&output->events.frame, &sample_output->frame);
@ -304,7 +306,9 @@ static void new_input_notify(struct wl_listener *listener, void *data) {
case WLR_INPUT_DEVICE_KEYBOARD:;
struct sample_keyboard *keyboard = calloc(1, sizeof(*keyboard));
assert(keyboard);
keyboard->wlr_keyboard = wlr_keyboard_from_input_device(device);
assert(keyboard->wlr_keyboard);
keyboard->state = state;
wl_signal_add(&device->events.destroy, &keyboard->destroy);
keyboard->destroy.notify = keyboard_destroy_notify;

View file

@ -1,3 +1,4 @@
#include <assert.h>
#include <drm_fourcc.h>
#include <getopt.h>
#include <math.h>
@ -118,6 +119,7 @@ static void new_output_notify(struct wl_listener *listener, void *data) {
wlr_output_init_render(output, sample->allocator, sample->renderer);
struct sample_output *sample_output = calloc(1, sizeof(*sample_output));
assert(sample_output);
sample_output->x_offs = sample_output->y_offs = 0;
sample_output->x_vel = sample_output->y_vel = 128;
@ -186,7 +188,9 @@ static void new_input_notify(struct wl_listener *listener, void *data) {
switch (device->type) {
case WLR_INPUT_DEVICE_KEYBOARD:;
struct sample_keyboard *keyboard = calloc(1, sizeof(*keyboard));
assert(keyboard);
keyboard->wlr_keyboard = wlr_keyboard_from_input_device(device);
assert(keyboard->wlr_keyboard);
keyboard->sample = sample;
wl_signal_add(&device->events.destroy, &keyboard->destroy);
keyboard->destroy.notify = keyboard_destroy_notify;

View file

@ -72,6 +72,7 @@ static void server_handle_new_output(struct wl_listener *listener, void *data) {
wlr_output_init_render(wlr_output, server->allocator, server->renderer);
struct output *output = calloc(1, sizeof(*output));
assert(output);
output->wlr = wlr_output;
output->server = server;
output->frame.notify = output_handle_frame;
@ -124,6 +125,7 @@ static void server_handle_new_surface(struct wl_listener *listener,
server->surface_offset += 50;
struct surface *surface = calloc(1, sizeof(*surface));
assert(surface);
surface->wlr = wlr_surface;
surface->commit.notify = surface_handle_commit;
wl_signal_add(&wlr_surface->events.commit, &surface->commit);

View file

@ -1,3 +1,4 @@
#include <assert.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
@ -97,6 +98,7 @@ static void new_output_notify(struct wl_listener *listener, void *data) {
wlr_output_init_render(output, sample->allocator, sample->renderer);
struct sample_output *sample_output = calloc(1, sizeof(*sample_output));
assert(sample_output);
sample_output->output = output;
sample_output->sample = sample;
wl_signal_add(&output->events.frame, &sample_output->frame);
@ -145,7 +147,9 @@ static void new_input_notify(struct wl_listener *listener, void *data) {
switch (device->type) {
case WLR_INPUT_DEVICE_KEYBOARD:;
struct sample_keyboard *keyboard = calloc(1, sizeof(*keyboard));
assert(keyboard);
keyboard->wlr_keyboard = wlr_keyboard_from_input_device(device);
assert(keyboard->wlr_keyboard);
keyboard->sample = sample;
wl_signal_add(&device->events.destroy, &keyboard->destroy);
keyboard->destroy.notify = keyboard_destroy_notify;

View file

@ -1,5 +1,6 @@
#undef _POSIX_C_SOURCE
#define _XOPEN_SOURCE 600 // for M_PI
#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
@ -271,6 +272,7 @@ static void new_output_notify(struct wl_listener *listener, void *data) {
wlr_output_init_render(output, sample->allocator, sample->renderer);
struct sample_output *sample_output = calloc(1, sizeof(*sample_output));
assert(sample_output);
sample_output->output = output;
sample_output->sample = sample;
wl_signal_add(&output->events.frame, &sample_output->frame);
@ -318,7 +320,9 @@ static void new_input_notify(struct wl_listener *listener, void *data) {
switch (device->type) {
case WLR_INPUT_DEVICE_KEYBOARD:;
struct sample_keyboard *keyboard = calloc(1, sizeof(*keyboard));
assert(keyboard);
keyboard->wlr_keyboard = wlr_keyboard_from_input_device(device);
assert(keyboard->wlr_keyboard);
keyboard->sample = sample;
wl_signal_add(&device->events.destroy, &keyboard->destroy);
keyboard->destroy.notify = keyboard_destroy_notify;
@ -341,7 +345,9 @@ static void new_input_notify(struct wl_listener *listener, void *data) {
break;
case WLR_INPUT_DEVICE_TABLET_PAD:;
struct tablet_pad_state *pstate = calloc(1, sizeof(*pstate));
assert(pstate);
pstate->wlr_tablet_pad = wlr_tablet_pad_from_input_device(device);
assert(pstate->wlr_tablet_pad);
pstate->sample = sample;
pstate->destroy.notify = tablet_pad_destroy_notify;
wl_signal_add(&device->events.destroy, &pstate->destroy);
@ -359,6 +365,7 @@ static void new_input_notify(struct wl_listener *listener, void *data) {
10 : tablet->height_mm;
struct tablet_tool_state *tstate = calloc(1, sizeof(*tstate));
assert(tstate);
tstate->wlr_tablet = tablet;
tstate->sample = sample;
tstate->destroy.notify = tablet_tool_destroy_notify;

View file

@ -1,3 +1,4 @@
#include <assert.h>
#include <drm_fourcc.h>
#include <math.h>
#include <stdint.h>
@ -103,6 +104,7 @@ static void touch_down_notify(struct wl_listener *listener, void *data) {
struct touch_state *tstate = wl_container_of(listener, tstate, down);
struct sample_state *sample = tstate->sample;
struct touch_point *point = calloc(1, sizeof(*point));
assert(point);
point->touch_id = event->touch_id;
point->x = event->x;
point->y = event->y;
@ -174,6 +176,7 @@ static void new_output_notify(struct wl_listener *listener, void *data) {
wlr_output_init_render(output, sample->allocator, sample->renderer);
struct sample_output *sample_output = calloc(1, sizeof(*sample_output));
assert(sample_output);
sample_output->output = output;
sample_output->sample = sample;
wl_signal_add(&output->events.frame, &sample_output->frame);
@ -221,6 +224,7 @@ static void new_input_notify(struct wl_listener *listener, void *data) {
switch (device->type) {
case WLR_INPUT_DEVICE_KEYBOARD:;
struct sample_keyboard *keyboard = calloc(1, sizeof(*keyboard));
assert(keyboard);
keyboard->wlr_keyboard = wlr_keyboard_from_input_device(device);
keyboard->sample = sample;
wl_signal_add(&device->events.destroy, &keyboard->destroy);
@ -244,6 +248,7 @@ static void new_input_notify(struct wl_listener *listener, void *data) {
break;
case WLR_INPUT_DEVICE_TOUCH:;
struct touch_state *tstate = calloc(1, sizeof(*tstate));
assert(tstate);
tstate->wlr_touch = wlr_touch_from_input_device(device);
tstate->sample = sample;
tstate->destroy.notify = touch_destroy_notify;

View file

@ -250,6 +250,7 @@ static void server_new_keyboard(struct tinywl_server *server,
struct wlr_keyboard *wlr_keyboard = wlr_keyboard_from_input_device(device);
struct tinywl_keyboard *keyboard = calloc(1, sizeof(*keyboard));
assert(keyboard);
keyboard->server = server;
keyboard->wlr_keyboard = wlr_keyboard;
@ -625,6 +626,7 @@ static void server_new_output(struct wl_listener *listener, void *data) {
/* Allocates and configures our state for this output */
struct tinywl_output *output = calloc(1, sizeof(*output));
assert(output);
output->wlr_output = wlr_output;
output->server = server;
@ -801,6 +803,7 @@ static void server_new_xdg_toplevel(struct wl_listener *listener, void *data) {
/* Allocate a tinywl_toplevel for this surface */
struct tinywl_toplevel *toplevel = calloc(1, sizeof(*toplevel));
assert(toplevel);
toplevel->server = server;
toplevel->xdg_toplevel = xdg_toplevel;
toplevel->scene_tree =
@ -859,6 +862,7 @@ static void server_new_xdg_popup(struct wl_listener *listener, void *data) {
struct wlr_xdg_popup *xdg_popup = data;
struct tinywl_popup *popup = calloc(1, sizeof(*popup));
assert(popup);
popup->xdg_popup = xdg_popup;
/* We must add xdg popups to the scene graph so they get rendered. The

View file

@ -197,6 +197,7 @@ static bool scene_buffer_point_accepts_input(struct wlr_scene_buffer *scene_buff
double *sx, double *sy) {
struct wlr_scene_surface *scene_surface =
wlr_scene_surface_try_from_buffer(scene_buffer);
assert(scene_surface);
*sx += scene_surface->clip.x;
*sy += scene_surface->clip.y;