fix segfault when JSIOCGAXMAP/JSIOCGBTNMAP dont work http://bugs.gentoo.org/132607 patch by Matt Anderson --- utils/jstest.c +++ utils/jstest.c @@ -76,6 +76,7 @@ int main (int argc, char **argv) char name[NAME_LENGTH] = "Unknown"; uint16_t btnmap[KEY_MAX - BTN_MISC + 1]; uint8_t axmap[ABS_MAX + 1]; + int btnmap_ok, axismap_ok; if (argc < 2 || argc > 3 || !strcmp("--help", argv[1])) { puts(""); @@ -99,21 +100,29 @@ int main (int argc, char **argv) ioctl(fd, JSIOCGAXES, &axes); ioctl(fd, JSIOCGBUTTONS, &buttons); ioctl(fd, JSIOCGNAME(NAME_LENGTH), name); - ioctl(fd, JSIOCGAXMAP, axmap); - ioctl(fd, JSIOCGBTNMAP, btnmap); + axismap_ok = ioctl(fd, JSIOCGAXMAP, axmap); + btnmap_ok = ioctl(fd, JSIOCGBTNMAP, btnmap); printf("Driver version is %d.%d.%d.\n", version >> 16, (version >> 8) & 0xff, version & 0xff); printf("Joystick (%s) has %d axes (", name, axes); - for (i = 0; i < axes; i++) - printf("%s%s", i > 0 ? ", " : "", axis_names[axmap[i]]); + if (!axismap_ok) { + for (i = 0; i < axes; i++) + printf("%s%s", i > 0 ? ", " : "", axis_names[axmap[i]]); + } else { + printf(" axismap never defined "); + } puts(")"); printf("and %d buttons (", buttons); - for (i = 0; i < buttons; i++) - printf("%s%s", i > 0 ? ", " : "", button_names[btnmap[i] - BTN_MISC]); + if (!btnmap_ok) { + for (i = 0; i < buttons; i++) + printf("%s%s", i > 0 ? ", " : "", button_names[btnmap[i] - BTN_MISC]); + } else { + printf(" buttonmap never defined "); + } puts(")."); printf("Testing ... (interrupt to exit)\n");