libi3/root_atom_contents: handle data of arbitrary length
Handle data fetched from xcb_get_property_unchecked with arbitrary length. This avoids having to rely on PATH_MAX macro where it is not necessary.
This commit is contained in:
parent
2eea82eb02
commit
eca5e4598a
@ -144,7 +144,7 @@ PANGO_LIBS := $(call ldflags_for_lib, cairo)
|
|||||||
PANGO_LIBS += $(call ldflags_for_lib, pangocairo)
|
PANGO_LIBS += $(call ldflags_for_lib, pangocairo)
|
||||||
|
|
||||||
# libi3
|
# libi3
|
||||||
LIBS = -L$(TOPDIR) -li3
|
LIBS = -L$(TOPDIR) -li3 -lm
|
||||||
|
|
||||||
## Platform-specific flags
|
## Platform-specific flags
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#include <xcb/xcb.h>
|
#include <xcb/xcb.h>
|
||||||
#include <xcb/xcb_aux.h>
|
#include <xcb/xcb_aux.h>
|
||||||
@ -31,6 +32,7 @@ char *root_atom_contents(const char *atomname, xcb_connection_t *provided_conn,
|
|||||||
xcb_intern_atom_cookie_t atom_cookie;
|
xcb_intern_atom_cookie_t atom_cookie;
|
||||||
xcb_intern_atom_reply_t *atom_reply;
|
xcb_intern_atom_reply_t *atom_reply;
|
||||||
char *content;
|
char *content;
|
||||||
|
size_t content_max_words = 256;
|
||||||
xcb_connection_t *conn = provided_conn;
|
xcb_connection_t *conn = provided_conn;
|
||||||
|
|
||||||
if (provided_conn == NULL &&
|
if (provided_conn == NULL &&
|
||||||
@ -50,12 +52,26 @@ char *root_atom_contents(const char *atomname, xcb_connection_t *provided_conn,
|
|||||||
xcb_get_property_cookie_t prop_cookie;
|
xcb_get_property_cookie_t prop_cookie;
|
||||||
xcb_get_property_reply_t *prop_reply;
|
xcb_get_property_reply_t *prop_reply;
|
||||||
prop_cookie = xcb_get_property_unchecked(conn, false, root, atom_reply->atom,
|
prop_cookie = xcb_get_property_unchecked(conn, false, root, atom_reply->atom,
|
||||||
XCB_GET_PROPERTY_TYPE_ANY, 0, PATH_MAX);
|
XCB_GET_PROPERTY_TYPE_ANY, 0, content_max_words);
|
||||||
prop_reply = xcb_get_property_reply(conn, prop_cookie, NULL);
|
prop_reply = xcb_get_property_reply(conn, prop_cookie, NULL);
|
||||||
if (prop_reply == NULL) {
|
if (prop_reply == NULL) {
|
||||||
free(atom_reply);
|
free(atom_reply);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
if (xcb_get_property_value_length(prop_reply) > 0 && prop_reply->bytes_after > 0) {
|
||||||
|
/* We received an incomplete value. Ask again but with a properly
|
||||||
|
* adjusted size. */
|
||||||
|
content_max_words += ceil(prop_reply->bytes_after / 4.0);
|
||||||
|
/* Repeat the request, with adjusted size */
|
||||||
|
free(prop_reply);
|
||||||
|
prop_cookie = xcb_get_property_unchecked(conn, false, root, atom_reply->atom,
|
||||||
|
XCB_GET_PROPERTY_TYPE_ANY, 0, content_max_words);
|
||||||
|
prop_reply = xcb_get_property_reply(conn, prop_cookie, NULL);
|
||||||
|
if (prop_reply == NULL) {
|
||||||
|
free(atom_reply);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (xcb_get_property_value_length(prop_reply) == 0) {
|
if (xcb_get_property_value_length(prop_reply) == 0) {
|
||||||
free(atom_reply);
|
free(atom_reply);
|
||||||
free(prop_reply);
|
free(prop_reply);
|
||||||
|
Loading…
Reference in New Issue
Block a user