From 7fe7bbf58cbb7f8a6c37520442e1b34bb6909b75 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Thu, 1 Feb 2018 16:31:59 +0100 Subject: [PATCH] Check empty string before strtol() There is no need to call strtol() if the input string is empty. --- app/src/main.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/src/main.c b/app/src/main.c index 6dc0fb32..d05c607b 100644 --- a/app/src/main.c +++ b/app/src/main.c @@ -65,8 +65,12 @@ static int parse_args(struct args *args, int argc, char *argv[]) { } case 'p': { char *endptr; + if (*optarg == '\0') { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid port parameter is empty"); + return -1; + } long value = strtol(optarg, &endptr, 0); - if (*optarg == '\0' || *endptr != '\0') { + if (*endptr != '\0') { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid port: %s", optarg); return -1; } @@ -79,8 +83,12 @@ static int parse_args(struct args *args, int argc, char *argv[]) { } case 'm': { char *endptr; + if (*optarg == '\0') { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Max size parameter is empty"); + return -1; + } long value = strtol(optarg, &endptr, 0); - if (*optarg == '\0' || *endptr != '\0') { + if (*endptr != '\0') { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid max size: %s", optarg); return -1; }