Check empty string before strtol()
There is no need to call strtol() if the input string is empty.
This commit is contained in:
parent
3bc63708b4
commit
7fe7bbf58c
1 changed files with 10 additions and 2 deletions
|
@ -65,8 +65,12 @@ static int parse_args(struct args *args, int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
case 'p': {
|
case 'p': {
|
||||||
char *endptr;
|
char *endptr;
|
||||||
|
if (*optarg == '\0') {
|
||||||
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid port parameter is empty");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
long value = strtol(optarg, &endptr, 0);
|
long value = strtol(optarg, &endptr, 0);
|
||||||
if (*optarg == '\0' || *endptr != '\0') {
|
if (*endptr != '\0') {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid port: %s", optarg);
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid port: %s", optarg);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -79,8 +83,12 @@ static int parse_args(struct args *args, int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
case 'm': {
|
case 'm': {
|
||||||
char *endptr;
|
char *endptr;
|
||||||
|
if (*optarg == '\0') {
|
||||||
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Max size parameter is empty");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
long value = strtol(optarg, &endptr, 0);
|
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);
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid max size: %s", optarg);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue