diff --git a/awesome.c b/awesome.c index cb632c194..9e1ca28b1 100644 --- a/awesome.c +++ b/awesome.c @@ -236,6 +236,8 @@ xerror(void *data __attribute__ ((unused)), xcb_generic_error_t *e) { xutil_error_t *err = xutil_get_error(e); + if(!err) + return 0; if(e->error_code == BadWindow || (e->error_code == BadMatch && err->request_code == XCB_SET_INPUT_FOCUS) diff --git a/common/xutil.c b/common/xutil.c index cbf754e17..5f607c8dc 100644 --- a/common/xutil.c +++ b/common/xutil.c @@ -19,9 +19,11 @@ * */ -/* strndup() */ +/* strndup(), asprintf() */ #define _GNU_SOURCE +#include + #include #include @@ -254,7 +256,7 @@ xutil_error_label[] = const char * xutil_request_label[] = { - "XCB_NONE", + "None", "CreateWindow", "ChangeWindowAttributes", "GetWindowAttributes", @@ -387,6 +389,10 @@ xutil_request_label[] = xutil_error_t * xutil_get_error(const xcb_generic_error_t *e) { + if(e->response_type != 0) + /* This is not an error, this _should_ not happen */ + return NULL; + xutil_error_t *err = p_new(xutil_error_t, 1); /* @@ -394,11 +400,21 @@ xutil_get_error(const xcb_generic_error_t *e) * out how it works BTW, seems to get a byte in 'pad' member * (second byte in second element of the array) */ - err->request_code = (e->response_type == 0 ? - *((uint8_t *) e + 10) : (e->response_type & 0x7f)); + err->request_code = *((uint8_t *) e + 10); - err->request_label = a_strdup(xutil_request_label[err->request_code]); - err->error_label = a_strdup(xutil_error_label[e->error_code]); + /* Extensions generally provide their own requests so we just + * store the request code */ + if(err->request_code >= (sizeof(xutil_request_label) / sizeof(char *))) + asprintf(&err->request_label, "%d", err->request_code); + else + err->request_label = a_strdup(xutil_request_label[err->request_code]); + + /* Extensions may also define their own errors, so just store the + * error_code */ + if(e->error_code >= (sizeof(xutil_error_label) / sizeof(char *))) + asprintf(&err->error_label, "%d", e->error_code); + else + err->error_label = a_strdup(xutil_error_label[e->error_code]); return err; }