mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-10-31 22:25:33 -04:00
xcb: xcb_get_setup() can return 0, so make sure we check it before using
This commit is contained in:
parent
24014e779c
commit
c0e045d003
1 changed files with 48 additions and 20 deletions
|
|
@ -27,6 +27,8 @@
|
||||||
|
|
||||||
#include "x11prop.h"
|
#include "x11prop.h"
|
||||||
|
|
||||||
|
#include <pulsecore/macro.h>
|
||||||
|
|
||||||
#include <xcb/xproto.h>
|
#include <xcb/xproto.h>
|
||||||
#include <xcb/xcb_atom.h>
|
#include <xcb/xcb_atom.h>
|
||||||
|
|
||||||
|
|
@ -34,16 +36,33 @@
|
||||||
|
|
||||||
void pa_x11_set_prop(xcb_connection_t *xcb, const char *name, const char *data) {
|
void pa_x11_set_prop(xcb_connection_t *xcb, const char *name, const char *data) {
|
||||||
xcb_screen_t *screen;
|
xcb_screen_t *screen;
|
||||||
xcb_atom_t a = xcb_atom_get(xcb, name);
|
const xcb_setup_t *s;
|
||||||
screen = xcb_setup_roots_iterator(xcb_get_setup(xcb)).data;
|
xcb_atom_t a;
|
||||||
xcb_change_property(xcb, XCB_PROP_MODE_REPLACE, screen->root, a, STRING, PA_XCB_FORMAT, (int) strlen(data), (const void*) data);
|
|
||||||
|
pa_assert(xcb);
|
||||||
|
pa_assert(name);
|
||||||
|
pa_assert(data);
|
||||||
|
|
||||||
|
if ((s = xcb_get_setup(xcb))) {
|
||||||
|
a = xcb_atom_get(xcb, name);
|
||||||
|
screen = xcb_setup_roots_iterator(s).data;
|
||||||
|
xcb_change_property(xcb, XCB_PROP_MODE_REPLACE, screen->root, a, STRING, PA_XCB_FORMAT, (int) strlen(data), (const void*) data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void pa_x11_del_prop(xcb_connection_t *xcb, const char *name) {
|
void pa_x11_del_prop(xcb_connection_t *xcb, const char *name) {
|
||||||
xcb_screen_t *screen;
|
xcb_screen_t *screen;
|
||||||
xcb_atom_t a = xcb_atom_get(xcb, name);
|
const xcb_setup_t *s;
|
||||||
screen = xcb_setup_roots_iterator(xcb_get_setup(xcb)).data;
|
xcb_atom_t a;
|
||||||
xcb_delete_property(xcb, screen->root, a);
|
|
||||||
|
pa_assert(xcb);
|
||||||
|
pa_assert(name);
|
||||||
|
|
||||||
|
if ((s = xcb_get_setup(xcb))) {
|
||||||
|
a = xcb_atom_get(xcb, name);
|
||||||
|
screen = xcb_setup_roots_iterator(s).data;
|
||||||
|
xcb_delete_property(xcb, screen->root, a);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char* pa_x11_get_prop(xcb_connection_t *xcb, const char *name, char *p, size_t l) {
|
char* pa_x11_get_prop(xcb_connection_t *xcb, const char *name, char *p, size_t l) {
|
||||||
|
|
@ -52,26 +71,35 @@ char* pa_x11_get_prop(xcb_connection_t *xcb, const char *name, char *p, size_t l
|
||||||
xcb_get_property_cookie_t req;
|
xcb_get_property_cookie_t req;
|
||||||
xcb_get_property_reply_t* prop = NULL;
|
xcb_get_property_reply_t* prop = NULL;
|
||||||
xcb_screen_t *screen;
|
xcb_screen_t *screen;
|
||||||
xcb_atom_t a = xcb_atom_get(xcb, name);
|
const xcb_setup_t *s;
|
||||||
screen = xcb_setup_roots_iterator(xcb_get_setup(xcb)).data;
|
xcb_atom_t a;
|
||||||
|
|
||||||
req = xcb_get_property(xcb, 0, screen->root, a, STRING, 0, (uint32_t)(l-1));
|
pa_assert(xcb);
|
||||||
prop = xcb_get_property_reply(xcb, req, NULL);
|
pa_assert(name);
|
||||||
|
pa_assert(p);
|
||||||
|
|
||||||
if (!prop)
|
if ((s = xcb_get_setup(xcb))) {
|
||||||
goto finish;
|
a = xcb_atom_get(xcb, name);
|
||||||
|
screen = xcb_setup_roots_iterator(s).data;
|
||||||
|
|
||||||
if (PA_XCB_FORMAT != prop->format)
|
req = xcb_get_property(xcb, 0, screen->root, a, STRING, 0, (uint32_t)(l-1));
|
||||||
goto finish;
|
prop = xcb_get_property_reply(xcb, req, NULL);
|
||||||
|
|
||||||
len = xcb_get_property_value_length(prop);
|
if (!prop)
|
||||||
if (len < 1 || len >= (int)l)
|
goto finish;
|
||||||
goto finish;
|
|
||||||
|
|
||||||
memcpy(p, xcb_get_property_value(prop), len);
|
if (PA_XCB_FORMAT != prop->format)
|
||||||
p[len] = 0;
|
goto finish;
|
||||||
|
|
||||||
ret = p;
|
len = xcb_get_property_value_length(prop);
|
||||||
|
if (len < 1 || len >= (int)l)
|
||||||
|
goto finish;
|
||||||
|
|
||||||
|
memcpy(p, xcb_get_property_value(prop), len);
|
||||||
|
p[len] = 0;
|
||||||
|
|
||||||
|
ret = p;
|
||||||
|
}
|
||||||
|
|
||||||
finish:
|
finish:
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue