1 parent 4df8b27 commit f68a5a3Copy full SHA for f68a5a3
1 file changed
evdev/input.c
@@ -310,24 +310,25 @@ get_sw_led_snd(PyObject *self, PyObject *args)
310
max = SW_MAX;
311
else if (evtype == EV_SND)
312
max = SND_MAX;
313
+ else
314
+ return NULL;
315
- char* bits = (char*) malloc(max/8);
- memset(bits, 0, sizeof(bits));
316
+ char bytes[(max+7)/8];
317
+ memset(bytes, 0, sizeof bytes);
318
319
if (evtype == EV_LED)
- ret = ioctl(fd, EVIOCGLED(sizeof(bits)), bits);
320
+ ret = ioctl(fd, EVIOCGLED(sizeof(bytes)), &bytes);
321
else if (evtype == EV_SW)
- ret = ioctl(fd, EVIOCGSW(sizeof(bits)), bits);
322
+ ret = ioctl(fd, EVIOCGSW(sizeof(bytes)), &bytes);
323
- ret = ioctl(fd, EVIOCGSND(sizeof(bits)), bits);
324
+ ret = ioctl(fd, EVIOCGSND(sizeof(bytes)), &bytes);
325
326
for (i=0 ; i<max ; i++) {
- if (test_bit(bits, i)) {
327
+ if (test_bit(bytes, i)) {
328
PyList_Append(res, Py_BuildValue("i", i));
329
}
330
331
- free(bits);
332
return res;
333
334
0 commit comments