From: Michal MalĂ˝ Date: Wed, 9 Jul 2014 10:02:01 +0000 (+0200) Subject: Use asprintf() instead of manual allocation to set up evdev_path X-Git-Url: https://gitweb.devoid-pointer.net/?a=commitdiff_plain;h=5e2fefe31914b7b4aba03a052d282e377f2465fe;p=LFSBench.git Use asprintf() instead of manual allocation to set up evdev_path --- 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 */