[xutil] check whether the error code and request are actually defined

This commit is contained in:
Arnaud Fontaine 2008-04-11 15:35:16 +01:00 committed by Julien Danjou
parent d1635db59f
commit 059829e37e
2 changed files with 24 additions and 6 deletions

View File

@ -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)

View File

@ -19,9 +19,11 @@
*
*/
/* strndup() */
/* strndup(), asprintf() */
#define _GNU_SOURCE
#include <stdio.h>
#include <xcb/xcb.h>
#include <xcb/xcb_atom.h>
@ -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,10 +400,20 @@ 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);
/* 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;