aboutsummaryrefslogtreecommitdiff
path: root/libX11/src/ModMap.c
diff options
context:
space:
mode:
Diffstat (limited to 'libX11/src/ModMap.c')
-rw-r--r--libX11/src/ModMap.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/libX11/src/ModMap.c b/libX11/src/ModMap.c
index c99bfdd5f..5c5b42612 100644
--- a/libX11/src/ModMap.c
+++ b/libX11/src/ModMap.c
@@ -28,6 +28,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
+#include <limits.h>
XModifierKeymap *
XGetModifierMapping(register Display *dpy)
@@ -41,13 +42,17 @@ XGetModifierMapping(register Display *dpy)
GetEmptyReq(GetModifierMapping, req);
(void) _XReply (dpy, (xReply *)&rep, 0, xFalse);
- nbytes = (unsigned long)rep.length << 2;
- res = (XModifierKeymap *) Xmalloc(sizeof (XModifierKeymap));
- if (res) res->modifiermap = (KeyCode *) Xmalloc ((unsigned) nbytes);
+ if (rep.length < (LONG_MAX >> 2)) {
+ nbytes = (unsigned long)rep.length << 2;
+ res = Xmalloc(sizeof (XModifierKeymap));
+ if (res)
+ res->modifiermap = Xmalloc (nbytes);
+ } else
+ res = NULL;
if ((! res) || (! res->modifiermap)) {
if (res) Xfree((char *) res);
res = (XModifierKeymap *) NULL;
- _XEatData(dpy, nbytes);
+ _XEatDataWords(dpy, rep.length);
} else {
_XReadPad(dpy, (char *) res->modifiermap, (long) nbytes);
res->max_keypermod = rep.numKeyPerModifier;
@@ -92,11 +97,11 @@ XSetModifierMapping(
XModifierKeymap *
XNewModifiermap(int keyspermodifier)
{
- XModifierKeymap *res = (XModifierKeymap *) Xmalloc((sizeof (XModifierKeymap)));
+ XModifierKeymap *res = Xmalloc((sizeof (XModifierKeymap)));
if (res) {
res->max_keypermod = keyspermodifier;
res->modifiermap = (keyspermodifier > 0 ?
- (KeyCode *) Xmalloc((unsigned) (8 * keyspermodifier))
+ Xmalloc(8 * keyspermodifier)
: (KeyCode *) NULL);
if (keyspermodifier && (res->modifiermap == NULL)) {
Xfree((char *) res);