[PATCH libevdev 4/4] uinput: check for asprintf failure

Peter Hutterer peter.hutterer at who-t.net
Mon Mar 17 21:21:02 PDT 2014


This doesn't really do much here, but strictly speaking: if asprintf returns
-1, devnode is undefined. So reset it to NULL to avoid weird pointers. And
also free the rest of the names if we ever have more than one device - which
also shouldn't happen.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 libevdev/libevdev-uinput.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libevdev/libevdev-uinput.c b/libevdev/libevdev-uinput.c
index 09b7044..0543bc4 100644
--- a/libevdev/libevdev-uinput.c
+++ b/libevdev/libevdev-uinput.c
@@ -179,7 +179,8 @@ fetch_device_node(const char *path)
 	/* ndev should only ever be 1 */
 
 	for (i = 0; i < ndev; i++) {
-		asprintf(&devnode, "/dev/input/%s", namelist[i]->d_name);
+		if (!devnode && asprintf(&devnode, "/dev/input/%s", namelist[i]->d_name) == -1)
+			devnode = NULL;
 		free(namelist[i]);
 	}
 
-- 
1.8.5.3



More information about the Input-tools mailing list