mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2026-04-17 06:46:39 -04:00
examples: assert on memory allocation
Also checks for NULL output in the `X_from_device` functions
This commit is contained in:
parent
ebef710746
commit
7cb206deb4
11 changed files with 39 additions and 1 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
|
#include <assert.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.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);
|
wlr_output_init_render(wlr_output, server->allocator, server->renderer);
|
||||||
|
|
||||||
struct output *output = calloc(1, sizeof(*output));
|
struct output *output = calloc(1, sizeof(*output));
|
||||||
|
assert(output);
|
||||||
output->wlr = wlr_output;
|
output->wlr = wlr_output;
|
||||||
output->server = server;
|
output->server = server;
|
||||||
output->frame.notify = output_handle_frame;
|
output->frame.notify = output_handle_frame;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include <assert.h>
|
||||||
#include <EGL/egl.h>
|
#include <EGL/egl.h>
|
||||||
#include <EGL/eglext.h>
|
#include <EGL/eglext.h>
|
||||||
#include <GLES2/gl2.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 wlr_surface *wlr_surface = data;
|
||||||
|
|
||||||
struct surface *surface = calloc(1, sizeof(*surface));
|
struct surface *surface = calloc(1, sizeof(*surface));
|
||||||
|
assert(surface);
|
||||||
surface->wlr = wlr_surface;
|
surface->wlr = wlr_surface;
|
||||||
|
|
||||||
surface->commit.notify = surface_handle_commit;
|
surface->commit.notify = surface_handle_commit;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include <assert.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.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);
|
wlr_output_init_render(wlr_output, server->allocator, server->renderer);
|
||||||
|
|
||||||
struct fullscreen_output *output = calloc(1, sizeof(*output));
|
struct fullscreen_output *output = calloc(1, sizeof(*output));
|
||||||
|
assert(output);
|
||||||
output->wlr_output = wlr_output;
|
output->wlr_output = wlr_output;
|
||||||
output->server = server;
|
output->server = server;
|
||||||
output->frame.notify = output_handle_frame;
|
output->frame.notify = output_handle_frame;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include <assert.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.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);
|
wlr_output_init_render(wlr_output, server->allocator, server->renderer);
|
||||||
|
|
||||||
struct output *output = calloc(1, sizeof(*output));
|
struct output *output = calloc(1, sizeof(*output));
|
||||||
|
assert(output);
|
||||||
output->wlr_output = wlr_output;
|
output->wlr_output = wlr_output;
|
||||||
output->server = server;
|
output->server = server;
|
||||||
wl_list_init(&output->surfaces);
|
wl_list_init(&output->surfaces);
|
||||||
|
|
@ -247,6 +249,7 @@ static void server_handle_new_surface(struct wl_listener *listener,
|
||||||
struct output *output;
|
struct output *output;
|
||||||
wl_list_for_each(output, &server->outputs, link) {
|
wl_list_for_each(output, &server->outputs, link) {
|
||||||
struct output_surface *output_surface = calloc(1, sizeof(*output_surface));
|
struct output_surface *output_surface = calloc(1, sizeof(*output_surface));
|
||||||
|
assert(output_surface);
|
||||||
output_surface->wlr_surface = wlr_surface;
|
output_surface->wlr_surface = wlr_surface;
|
||||||
output_surface->server = server;
|
output_surface->server = server;
|
||||||
output_surface->destroy.notify = output_surface_handle_destroy;
|
output_surface->destroy.notify = output_surface_handle_destroy;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include <assert.h>
|
||||||
#include <drm_fourcc.h>
|
#include <drm_fourcc.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <math.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);
|
wlr_output_init_render(output, sample->allocator, sample->renderer);
|
||||||
|
|
||||||
struct sample_output *sample_output = calloc(1, sizeof(*sample_output));
|
struct sample_output *sample_output = calloc(1, sizeof(*sample_output));
|
||||||
|
assert(sample_output);
|
||||||
wlr_output_layout_add_auto(sample->layout, output);
|
wlr_output_layout_add_auto(sample->layout, output);
|
||||||
sample_output->output = output;
|
sample_output->output = output;
|
||||||
sample_output->sample = sample;
|
sample_output->sample = sample;
|
||||||
|
|
@ -235,7 +237,9 @@ static void new_input_notify(struct wl_listener *listener, void *data) {
|
||||||
switch (device->type) {
|
switch (device->type) {
|
||||||
case WLR_INPUT_DEVICE_KEYBOARD:;
|
case WLR_INPUT_DEVICE_KEYBOARD:;
|
||||||
struct sample_keyboard *keyboard = calloc(1, sizeof(*keyboard));
|
struct sample_keyboard *keyboard = calloc(1, sizeof(*keyboard));
|
||||||
|
assert(keyboard);
|
||||||
keyboard->wlr_keyboard = wlr_keyboard_from_input_device(device);
|
keyboard->wlr_keyboard = wlr_keyboard_from_input_device(device);
|
||||||
|
assert(keyboard->wlr_keyboard);
|
||||||
keyboard->sample = sample;
|
keyboard->sample = sample;
|
||||||
wl_signal_add(&device->events.destroy, &keyboard->destroy);
|
wl_signal_add(&device->events.destroy, &keyboard->destroy);
|
||||||
keyboard->destroy.notify = keyboard_destroy_notify;
|
keyboard->destroy.notify = keyboard_destroy_notify;
|
||||||
|
|
|
||||||
|
|
@ -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 sample_state *sample = wl_container_of(listener, sample, touch_down);
|
||||||
struct wlr_touch_down_event *event = data;
|
struct wlr_touch_down_event *event = data;
|
||||||
struct touch_point *point = calloc(1, sizeof(*point));
|
struct touch_point *point = calloc(1, sizeof(*point));
|
||||||
|
assert(point);
|
||||||
point->touch_id = event->touch_id;
|
point->touch_id = event->touch_id;
|
||||||
point->x = event->x;
|
point->x = event->x;
|
||||||
point->y = event->y;
|
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);
|
wlr_output_init_render(output, sample->allocator, sample->renderer);
|
||||||
|
|
||||||
struct sample_output *sample_output = calloc(1, sizeof(*sample_output));
|
struct sample_output *sample_output = calloc(1, sizeof(*sample_output));
|
||||||
|
assert(sample_output);
|
||||||
sample_output->output = output;
|
sample_output->output = output;
|
||||||
sample_output->state = sample;
|
sample_output->state = sample;
|
||||||
wl_signal_add(&output->events.frame, &sample_output->frame);
|
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:;
|
case WLR_INPUT_DEVICE_KEYBOARD:;
|
||||||
struct sample_keyboard *keyboard = calloc(1, sizeof(*keyboard));
|
struct sample_keyboard *keyboard = calloc(1, sizeof(*keyboard));
|
||||||
|
assert(keyboard);
|
||||||
keyboard->wlr_keyboard = wlr_keyboard_from_input_device(device);
|
keyboard->wlr_keyboard = wlr_keyboard_from_input_device(device);
|
||||||
|
assert(keyboard->wlr_keyboard);
|
||||||
keyboard->state = state;
|
keyboard->state = state;
|
||||||
wl_signal_add(&device->events.destroy, &keyboard->destroy);
|
wl_signal_add(&device->events.destroy, &keyboard->destroy);
|
||||||
keyboard->destroy.notify = keyboard_destroy_notify;
|
keyboard->destroy.notify = keyboard_destroy_notify;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include <assert.h>
|
||||||
#include <drm_fourcc.h>
|
#include <drm_fourcc.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <math.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);
|
wlr_output_init_render(output, sample->allocator, sample->renderer);
|
||||||
|
|
||||||
struct sample_output *sample_output = calloc(1, sizeof(*sample_output));
|
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_offs = sample_output->y_offs = 0;
|
||||||
sample_output->x_vel = sample_output->y_vel = 128;
|
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) {
|
switch (device->type) {
|
||||||
case WLR_INPUT_DEVICE_KEYBOARD:;
|
case WLR_INPUT_DEVICE_KEYBOARD:;
|
||||||
struct sample_keyboard *keyboard = calloc(1, sizeof(*keyboard));
|
struct sample_keyboard *keyboard = calloc(1, sizeof(*keyboard));
|
||||||
|
assert(keyboard);
|
||||||
keyboard->wlr_keyboard = wlr_keyboard_from_input_device(device);
|
keyboard->wlr_keyboard = wlr_keyboard_from_input_device(device);
|
||||||
|
assert(keyboard->wlr_keyboard);
|
||||||
keyboard->sample = sample;
|
keyboard->sample = sample;
|
||||||
wl_signal_add(&device->events.destroy, &keyboard->destroy);
|
wl_signal_add(&device->events.destroy, &keyboard->destroy);
|
||||||
keyboard->destroy.notify = keyboard_destroy_notify;
|
keyboard->destroy.notify = keyboard_destroy_notify;
|
||||||
|
|
|
||||||
|
|
@ -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);
|
wlr_output_init_render(wlr_output, server->allocator, server->renderer);
|
||||||
|
|
||||||
struct output *output = calloc(1, sizeof(*output));
|
struct output *output = calloc(1, sizeof(*output));
|
||||||
|
assert(output);
|
||||||
output->wlr = wlr_output;
|
output->wlr = wlr_output;
|
||||||
output->server = server;
|
output->server = server;
|
||||||
output->frame.notify = output_handle_frame;
|
output->frame.notify = output_handle_frame;
|
||||||
|
|
@ -124,6 +125,7 @@ static void server_handle_new_surface(struct wl_listener *listener,
|
||||||
server->surface_offset += 50;
|
server->surface_offset += 50;
|
||||||
|
|
||||||
struct surface *surface = calloc(1, sizeof(*surface));
|
struct surface *surface = calloc(1, sizeof(*surface));
|
||||||
|
assert(surface);
|
||||||
surface->wlr = wlr_surface;
|
surface->wlr = wlr_surface;
|
||||||
surface->commit.notify = surface_handle_commit;
|
surface->commit.notify = surface_handle_commit;
|
||||||
wl_signal_add(&wlr_surface->events.commit, &surface->commit);
|
wl_signal_add(&wlr_surface->events.commit, &surface->commit);
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include <assert.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.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);
|
wlr_output_init_render(output, sample->allocator, sample->renderer);
|
||||||
|
|
||||||
struct sample_output *sample_output = calloc(1, sizeof(*sample_output));
|
struct sample_output *sample_output = calloc(1, sizeof(*sample_output));
|
||||||
|
assert(sample_output);
|
||||||
sample_output->output = output;
|
sample_output->output = output;
|
||||||
sample_output->sample = sample;
|
sample_output->sample = sample;
|
||||||
wl_signal_add(&output->events.frame, &sample_output->frame);
|
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) {
|
switch (device->type) {
|
||||||
case WLR_INPUT_DEVICE_KEYBOARD:;
|
case WLR_INPUT_DEVICE_KEYBOARD:;
|
||||||
struct sample_keyboard *keyboard = calloc(1, sizeof(*keyboard));
|
struct sample_keyboard *keyboard = calloc(1, sizeof(*keyboard));
|
||||||
|
assert(keyboard);
|
||||||
keyboard->wlr_keyboard = wlr_keyboard_from_input_device(device);
|
keyboard->wlr_keyboard = wlr_keyboard_from_input_device(device);
|
||||||
|
assert(keyboard->wlr_keyboard);
|
||||||
keyboard->sample = sample;
|
keyboard->sample = sample;
|
||||||
wl_signal_add(&device->events.destroy, &keyboard->destroy);
|
wl_signal_add(&device->events.destroy, &keyboard->destroy);
|
||||||
keyboard->destroy.notify = keyboard_destroy_notify;
|
keyboard->destroy.notify = keyboard_destroy_notify;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
#undef _POSIX_C_SOURCE
|
#undef _POSIX_C_SOURCE
|
||||||
#define _XOPEN_SOURCE 600 // for M_PI
|
#define _XOPEN_SOURCE 600 // for M_PI
|
||||||
|
#include <assert.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.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);
|
wlr_output_init_render(output, sample->allocator, sample->renderer);
|
||||||
|
|
||||||
struct sample_output *sample_output = calloc(1, sizeof(*sample_output));
|
struct sample_output *sample_output = calloc(1, sizeof(*sample_output));
|
||||||
|
assert(sample_output);
|
||||||
sample_output->output = output;
|
sample_output->output = output;
|
||||||
sample_output->sample = sample;
|
sample_output->sample = sample;
|
||||||
wl_signal_add(&output->events.frame, &sample_output->frame);
|
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) {
|
switch (device->type) {
|
||||||
case WLR_INPUT_DEVICE_KEYBOARD:;
|
case WLR_INPUT_DEVICE_KEYBOARD:;
|
||||||
struct sample_keyboard *keyboard = calloc(1, sizeof(*keyboard));
|
struct sample_keyboard *keyboard = calloc(1, sizeof(*keyboard));
|
||||||
|
assert(keyboard);
|
||||||
keyboard->wlr_keyboard = wlr_keyboard_from_input_device(device);
|
keyboard->wlr_keyboard = wlr_keyboard_from_input_device(device);
|
||||||
|
assert(keyboard->wlr_keyboard);
|
||||||
keyboard->sample = sample;
|
keyboard->sample = sample;
|
||||||
wl_signal_add(&device->events.destroy, &keyboard->destroy);
|
wl_signal_add(&device->events.destroy, &keyboard->destroy);
|
||||||
keyboard->destroy.notify = keyboard_destroy_notify;
|
keyboard->destroy.notify = keyboard_destroy_notify;
|
||||||
|
|
@ -341,7 +345,9 @@ static void new_input_notify(struct wl_listener *listener, void *data) {
|
||||||
break;
|
break;
|
||||||
case WLR_INPUT_DEVICE_TABLET_PAD:;
|
case WLR_INPUT_DEVICE_TABLET_PAD:;
|
||||||
struct tablet_pad_state *pstate = calloc(1, sizeof(*pstate));
|
struct tablet_pad_state *pstate = calloc(1, sizeof(*pstate));
|
||||||
|
assert(pstate);
|
||||||
pstate->wlr_tablet_pad = wlr_tablet_pad_from_input_device(device);
|
pstate->wlr_tablet_pad = wlr_tablet_pad_from_input_device(device);
|
||||||
|
assert(pstate->wlr_tablet_pad);
|
||||||
pstate->sample = sample;
|
pstate->sample = sample;
|
||||||
pstate->destroy.notify = tablet_pad_destroy_notify;
|
pstate->destroy.notify = tablet_pad_destroy_notify;
|
||||||
wl_signal_add(&device->events.destroy, &pstate->destroy);
|
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;
|
10 : tablet->height_mm;
|
||||||
|
|
||||||
struct tablet_tool_state *tstate = calloc(1, sizeof(*tstate));
|
struct tablet_tool_state *tstate = calloc(1, sizeof(*tstate));
|
||||||
|
assert(tstate);
|
||||||
tstate->wlr_tablet = tablet;
|
tstate->wlr_tablet = tablet;
|
||||||
tstate->sample = sample;
|
tstate->sample = sample;
|
||||||
tstate->destroy.notify = tablet_tool_destroy_notify;
|
tstate->destroy.notify = tablet_tool_destroy_notify;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include <assert.h>
|
||||||
#include <drm_fourcc.h>
|
#include <drm_fourcc.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdint.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 touch_state *tstate = wl_container_of(listener, tstate, down);
|
||||||
struct sample_state *sample = tstate->sample;
|
struct sample_state *sample = tstate->sample;
|
||||||
struct touch_point *point = calloc(1, sizeof(*point));
|
struct touch_point *point = calloc(1, sizeof(*point));
|
||||||
|
assert(point);
|
||||||
point->touch_id = event->touch_id;
|
point->touch_id = event->touch_id;
|
||||||
point->x = event->x;
|
point->x = event->x;
|
||||||
point->y = event->y;
|
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);
|
wlr_output_init_render(output, sample->allocator, sample->renderer);
|
||||||
|
|
||||||
struct sample_output *sample_output = calloc(1, sizeof(*sample_output));
|
struct sample_output *sample_output = calloc(1, sizeof(*sample_output));
|
||||||
|
assert(sample_output);
|
||||||
sample_output->output = output;
|
sample_output->output = output;
|
||||||
sample_output->sample = sample;
|
sample_output->sample = sample;
|
||||||
wl_signal_add(&output->events.frame, &sample_output->frame);
|
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) {
|
switch (device->type) {
|
||||||
case WLR_INPUT_DEVICE_KEYBOARD:;
|
case WLR_INPUT_DEVICE_KEYBOARD:;
|
||||||
struct sample_keyboard *keyboard = calloc(1, sizeof(*keyboard));
|
struct sample_keyboard *keyboard = calloc(1, sizeof(*keyboard));
|
||||||
|
assert(keyboard);
|
||||||
keyboard->wlr_keyboard = wlr_keyboard_from_input_device(device);
|
keyboard->wlr_keyboard = wlr_keyboard_from_input_device(device);
|
||||||
keyboard->sample = sample;
|
keyboard->sample = sample;
|
||||||
wl_signal_add(&device->events.destroy, &keyboard->destroy);
|
wl_signal_add(&device->events.destroy, &keyboard->destroy);
|
||||||
|
|
@ -244,6 +248,7 @@ static void new_input_notify(struct wl_listener *listener, void *data) {
|
||||||
break;
|
break;
|
||||||
case WLR_INPUT_DEVICE_TOUCH:;
|
case WLR_INPUT_DEVICE_TOUCH:;
|
||||||
struct touch_state *tstate = calloc(1, sizeof(*tstate));
|
struct touch_state *tstate = calloc(1, sizeof(*tstate));
|
||||||
|
assert(tstate);
|
||||||
tstate->wlr_touch = wlr_touch_from_input_device(device);
|
tstate->wlr_touch = wlr_touch_from_input_device(device);
|
||||||
tstate->sample = sample;
|
tstate->sample = sample;
|
||||||
tstate->destroy.notify = touch_destroy_notify;
|
tstate->destroy.notify = touch_destroy_notify;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue