[Xcb] [PATCH 1/2] Make some functions also work on error connections

Uli Schlachter psychon at znc.in
Mon Aug 18 01:38:41 PDT 2014

There is no technical reason why xcb_get_setup() and xcb_get_file_descriptor()
shouldn't work on non-static error connections. They cannot be used for many
useful things, but at least they work.

This works around bugs in lots of programs out there which assume that
xcb_get_setup() does not return NULL and which just happily dereference the
results. Since xcb_connect() never returns NULL, it's a bit weird that
xcb_get_setup() can do so. xcb_get_file_descriptor() is just modified since this
can be done here equally easily and because the fd isn't closed until the final
xcb_disconnect() on the error connection.

Non-static error connections are connections which entered an error state after
xcb_connect() succeeded. If something goes wrong in establishing a connection,
xcb_connect() will return a static error connection which doesn't have the
fields used here.

Signed-off-by: Uli Schlachter <psychon at znc.in>
 src/xcb_conn.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/xcb_conn.c b/src/xcb_conn.c
index fa50985..15f707a 100644
--- a/src/xcb_conn.c
+++ b/src/xcb_conn.c
@@ -288,7 +288,7 @@ static int write_vec(xcb_connection_t *c, struct iovec **vector, int *count)
 const xcb_setup_t *xcb_get_setup(xcb_connection_t *c)
-    if(c->has_error)
+    if(is_static_error_conn(c))
         return 0;
     /* doesn't need locking because it's never written to. */
     return c->setup;
@@ -296,7 +296,7 @@ const xcb_setup_t *xcb_get_setup(xcb_connection_t *c)
 int xcb_get_file_descriptor(xcb_connection_t *c)
-    if(c->has_error)
+    if(is_static_error_conn(c))
         return -1;
     /* doesn't need locking because it's never written to. */
     return c->fd;

More information about the Xcb mailing list