From 8174acdccbe039b8cf8cbefce6fbbf24ce0a5eaf Mon Sep 17 00:00:00 2001 From: Federico Angelilli Date: Mon, 13 Nov 2023 16:31:09 +0100 Subject: Handle errors in `intern_atom` and fix randr version check --- x11.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/x11.c b/x11.c index 47c3319..fb7cddf 100644 --- a/x11.c +++ b/x11.c @@ -41,9 +41,14 @@ typedef struct { static xcb_atom_t intern_atom(Window *win, const char *atom) { - // TODO: Error handling + xcb_generic_error_t *error; xcb_intern_atom_cookie_t cookie = xcb_intern_atom(win->connection, false, strlen(atom), atom); - return xcb_intern_atom_reply(win->connection, cookie, NULL)->atom; + xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(win->connection, cookie, &error); + + g_assert_null(error); + xcb_atom_t id = reply->atom; + g_free(reply); + return id; } static gboolean xcb_source_check(GSource *source) @@ -154,8 +159,9 @@ Window *window_create(void) version_cookie, &error); + g_assert_null(error); log_debug("RandR version %d.%d", randr_version->major_version, randr_version->minor_version); - g_assert_true(error == NULL || randr_version->major_version < 1); + g_assert_cmpint(randr_version->major_version, >=, 1); xcb_randr_get_screen_info_cookie_t cookie = xcb_randr_get_screen_info(win->connection, win->screen->root); xcb_randr_get_screen_info_reply_t *info_reply = xcb_randr_get_screen_info_reply(win->connection, cookie, &error); -- cgit v1.2.3