If no match is found within the 'while' loop, the value of 'ndevices' will be -1 at the point we reach 'if (!ndevices)' since we use the post-decrement operator. In addition to never producing the expected error message, this also results in a NULL dereference immediately afterwards.
Signed-off-by: Jason Gerecke <killert...@gmail.com> --- Changes in v2: * Changed from a pre-decrement 'while' to a 'for' loop. The former wouldn't work right with ndevices == 0 and would have required a second 'Unable to locate device' error message. tools/xsetwacom.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/xsetwacom.c b/tools/xsetwacom.c index 276f7dd..beb4f25 100644 --- a/tools/xsetwacom.c +++ b/tools/xsetwacom.c @@ -1758,14 +1758,15 @@ static void get_mode(Display *dpy, XDevice *dev, param_t* param, int argc, char XValuatorInfoPtr v; info = XListInputDevices(dpy, &ndevices); - while(ndevices--) + + for (i = 0; i < ndevices; i++) { - d = &info[ndevices]; + d = &info[i]; if (d->id == dev->device_id) break; } - if (!ndevices) /* device id 0 is reserved and can't be our device */ + if (i >= ndevices) { fprintf(stderr, "Unable to locate device.\n"); return; -- 2.1.0 ------------------------------------------------------------------------------ Slashdot TV. Video for Nerds. Stuff that Matters. http://pubads.g.doubleclick.net/gampad/clk?id=160591471&iu=/4140/ostg.clktrk _______________________________________________ Linuxwacom-devel mailing list Linuxwacom-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel