diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2016-10-13 13:33:11 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2016-10-13 13:50:06 +1000 |
commit | 43904c9c5a0f5750a03a9bd8c96ccda182eb5a9a (patch) | |
tree | d44f3efacbf7319a26fc38486e0c02af66033ca4 /src/XListDev.c | |
parent | b843fe1c0a6b4dbaae9f364042c6a247249305ef (diff) |
XListInputDevices: don't touch ndevices in case of error
We used to always set *ndevices to the number of devices returned by the
server. This magically worked because we pretty much never returned an error
except on faulty server or library implementations. With 19a9cd60 we now have
more chances of getting an error, so the polite thing is to just leave *ndevices
alone when we error out.
Document it as such in the man page, just in case someone accidentally reads
it.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
CC: Niels Ole Salscheider <niels_ole@salscheider-online.de>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Diffstat (limited to 'src/XListDev.c')
-rw-r--r-- | src/XListDev.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/XListDev.c b/src/XListDev.c index e4bd3d5..dda6011 100644 --- a/src/XListDev.c +++ b/src/XListDev.c @@ -175,7 +175,7 @@ ParseClassInfo(xAnyClassPtr *any, XAnyClassPtr *Any, int num_classes) XDeviceInfo * XListInputDevices( register Display *dpy, - int *ndevices) + int *ndevices_return) { size_t s, size; xListInputDevicesReq *req; @@ -190,6 +190,7 @@ XListInputDevices( int i; unsigned long rlen; XExtDisplayInfo *info = XInput_find_display(dpy); + int ndevices; LockDisplay(dpy); if (_XiCheckExtInit(dpy, XInput_Initial_Release, info) == -1) @@ -205,8 +206,8 @@ XListInputDevices( return (XDeviceInfo *) NULL; } - if ((*ndevices = rep.ndevices)) { /* at least 1 input device */ - size = *ndevices * sizeof(XDeviceInfo); + if ((ndevices = rep.ndevices)) { /* at least 1 input device */ + size = ndevices * sizeof(XDeviceInfo); if (rep.length < (INT_MAX >> 2)) { rlen = rep.length << 2; /* multiply length by 4 */ slist = list = Xmalloc(rlen); @@ -219,17 +220,17 @@ XListInputDevices( } _XRead(dpy, (char *)list, rlen); - any = (xAnyClassPtr) ((char *)list + (*ndevices * sizeof(xDeviceInfo))); + any = (xAnyClassPtr) ((char *)list + (ndevices * sizeof(xDeviceInfo))); sav_any = any; end = (char *)list + rlen; - for (i = 0; i < *ndevices; i++, list++) { + for (i = 0; i < ndevices; i++, list++) { if(SizeClassInfo(&any, end - (char *)any, (int)list->num_classes, &s)) goto out; size += s; } Nptr = ((unsigned char *)list) + rlen; - for (i = 0, nptr = (unsigned char *)any; i < *ndevices; i++) { + for (i = 0, nptr = (unsigned char *)any; i < ndevices; i++) { if (nptr >= Nptr) goto out; size += *nptr + 1; @@ -245,10 +246,10 @@ XListInputDevices( } sclist = clist; Any = (XAnyClassPtr) ((char *)clist + - (*ndevices * sizeof(XDeviceInfo))); + (ndevices * sizeof(XDeviceInfo))); list = slist; any = sav_any; - for (i = 0; i < *ndevices; i++, list++, clist++) { + for (i = 0; i < ndevices; i++, list++, clist++) { clist->type = list->type; clist->id = list->id; clist->use = list->use; @@ -261,7 +262,7 @@ XListInputDevices( clist = sclist; nptr = (unsigned char *)any; Nptr = (unsigned char *)Any; - for (i = 0; i < *ndevices; i++, clist++) { + for (i = 0; i < ndevices; i++, clist++) { clist->name = (char *)Nptr; memcpy(Nptr, nptr + 1, *nptr); Nptr += (*nptr); @@ -270,6 +271,8 @@ XListInputDevices( } } + *ndevices_return = ndevices; + out: XFree((char *)slist); UnlockDisplay(dpy); |