From 5e2fefe31914b7b4aba03a052d282e377f2465fe Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michal=20Mal=C3=BD?= Date: Wed, 9 Jul 2014 12:02:01 +0200 Subject: [PATCH] Use asprintf() instead of manual allocation to set up evdev_path --- main.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/main.c b/main.c index 69bb1be..5738a61 100644 --- a/main.c +++ b/main.c @@ -31,6 +31,8 @@ int exit_app; int main(int argc, char** argv) { + int ret; + if (geteuid() != 0) { cap_t caps = cap_get_proc(); cap_flag_value_t capfv; @@ -63,10 +65,12 @@ int main(int argc, char** argv) /* Check arguments */ if (argc != 2) { printf("No arguments given, assuming that \"/dev/input/event0\" is the keyboard.\n"); - evdev_path = "/dev/input/event0"; - } else { - evdev_path = malloc(strlen(argv[1])*sizeof(char) + 1); - strcpy(evdev_path, argv[1]); + ret = asprintf(&evdev_path, "/dev/input/event0"); + } else + ret = asprintf(&evdev_path, "%s", argv[1]); + if (ret < 0) { + fprintf(stderr, "CRTITICAL: Cannot set up event device path\n"); + return -1; } /* Setup threading data */ -- 2.43.5