examples: assert on memory allocation

Also checks for NULL output in the `X_from_device` functions
This commit is contained in:
Simon Zeni 2024-04-08 10:11:50 -04:00
parent ebef710746
commit 7cb206deb4
11 changed files with 39 additions and 1 deletions

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;