summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2013-03-01 20:54:24 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2013-05-09 18:59:50 -0700
commit9f5d83706543696fc944c1835a403938c06f2cc5 (patch)
tree9c268da99df9fb0de263668681b3bce02dd37e39
parentd7f04c340ade3834e603c23d543132e1ee4e0c63 (diff)
Add _XEatDataWords to discard a given number of 32-bit words of reply data
Matches the units of the length field in X protocol replies, and provides a single implementation of overflow checking to avoid having to replicate those checks in every caller. Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com> Reviewed-by: Matthieu Herrb <matthieu.herrb@laas.fr>
-rw-r--r--include/X11/Xlibint.h4
-rw-r--r--src/xcb_io.c17
2 files changed, 21 insertions, 0 deletions
diff --git a/include/X11/Xlibint.h b/include/X11/Xlibint.h
index 06395b32..d63a5343 100644
--- a/include/X11/Xlibint.h
+++ b/include/X11/Xlibint.h
@@ -855,6 +855,10 @@ extern void _XEatData(
Display* /* dpy */,
unsigned long /* n */
);
+extern void _XEatDataWords(
+ Display* /* dpy */,
+ unsigned long /* n */
+);
extern char *_XAllocScratch(
Display* /* dpy */,
unsigned long /* nbytes */
diff --git a/src/xcb_io.c b/src/xcb_io.c
index 300ef571..727c6c79 100644
--- a/src/xcb_io.c
+++ b/src/xcb_io.c
@@ -19,6 +19,7 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
+#include <limits.h>
#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
#endif
@@ -757,3 +758,19 @@ void _XEatData(Display *dpy, unsigned long n)
dpy->xcb->reply_consumed += n;
_XFreeReplyData(dpy, False);
}
+
+/*
+ * Read and discard "n" 32-bit words of data
+ * Matches the units of the length field in X protocol replies, and provides
+ * a single implementation of overflow checking to avoid having to replicate
+ * those checks in every caller.
+ */
+void _XEatDataWords(Display *dpy, unsigned long n)
+{
+ if (n < ((INT_MAX - dpy->xcb->reply_consumed) >> 2))
+ dpy->xcb->reply_consumed += (n << 2);
+ else
+ /* Overflow would happen, so just eat the rest of the reply */
+ dpy->xcb->reply_consumed = dpy->xcb->reply_length;
+ _XFreeReplyData(dpy, False);
+}