From 0551d63b5f8777cb1bc54851b6d932873283399c Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Mon, 19 Feb 2024 21:48:35 +0000 Subject: [PATCH] atom: fix segfault when atom is not in the cache Signed-off-by: Yuxuan Shui --- src/atom.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/atom.c b/src/atom.c index 33321a1c..f4b97ebc 100644 --- a/src/atom.c +++ b/src/atom.c @@ -75,7 +75,11 @@ xcb_atom_t get_atom(struct atom *a, const char *key, size_t keylen, xcb_connecti xcb_atom_t get_atom_cached(struct atom *a, const char *key, size_t keylen) { auto atoms = container_of(a, struct atom_impl, base); - return cache_entry(cache_get(&atoms->c, key, keylen), struct atom_entry, entry)->atom; + auto entry = cache_get(&atoms->c, key, keylen); + if (!entry) { + return XCB_NONE; + } + return cache_entry(entry, struct atom_entry, entry)->atom; } const char *get_atom_name(struct atom *a, xcb_atom_t atom, xcb_connection_t *c) {