diff options
author | Dmitry Torokhov <dtor@chromium.org> | 2017-09-27 10:58:31 -0700 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2017-09-29 07:06:18 +1000 |
commit | fe82803c31770cc99637cf040b21d29a992d086d (patch) | |
tree | d42127822b921ba9bc533658aeaf89a6440d5945 | |
parent | ac0c41ca9522851bc1b3389cf8798e54bde465bd (diff) |
Do not ignore return values of scanf/asprintf
The functions are often declared as "warn unused result", which causes
compiler time warnings. Invalid user input may also lead to not entirely
correct utility behavior.
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r-- | evtest.c | 17 |
1 files changed, 9 insertions, 8 deletions
@@ -867,7 +867,7 @@ static int is_event_device(const struct dirent *dir) { static char* scan_devices(void) { struct dirent **namelist; - int i, ndev, devnum; + int i, ndev, devnum, match; char *filename; int max_device = 0; @@ -893,22 +893,23 @@ static char* scan_devices(void) fprintf(stderr, "%s: %s\n", fname, name); close(fd); - sscanf(namelist[i]->d_name, "event%d", &devnum); - if (devnum > max_device) + match = sscanf(namelist[i]->d_name, "event%d", &devnum); + if (match >= 1 && devnum > max_device) max_device = devnum; free(namelist[i]); } fprintf(stderr, "Select the device event number [0-%d]: ", max_device); - scanf("%d", &devnum); - if (devnum > max_device || devnum < 0) + match = scanf("%d", &devnum); + if (match < 1 || devnum > max_device || devnum < 0) return NULL; - asprintf(&filename, "%s/%s%d", - DEV_INPUT_EVENT, EVENT_DEV_NAME, - devnum); + if (asprintf(&filename, "%s/%s%d", + DEV_INPUT_EVENT, EVENT_DEV_NAME, + devnum) < 0) + return NULL; return filename; } |