Skip to content
This repository has been archived by the owner on May 24, 2022. It is now read-only.

Commit

Permalink
Fix error handling of NCORES command line parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsta authored and jedisct1 committed Jul 10, 2011
1 parent b57637f commit 0fe0502
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions stud.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ typedef struct stud_options {
char *FRONT_PORT;
char *BACK_IP;
char *BACK_PORT;
int NCORES;
long NCORES;
char *CERT_FILE;
char *CIPHER_SUITE;
} stud_options;
Expand Down Expand Up @@ -736,9 +736,13 @@ static void parse_cli(int argc, char **argv) {
break;

case 'n':
errno = 0;
OPTIONS.NCORES = strtol(optarg, NULL, 10);
if (errno || OPTIONS.NCORES < 1 || OPTIONS.NCORES > 128)
if ((errno == ERANGE &&
(OPTIONS.NCORES == LONG_MAX || OPTIONS.NCORES == LONG_MIN)) ||
OPTIONS.NCORES < 1 || OPTIONS.NCORES > 128) {
usage_fail(prog, "invalid option for -n CORES; please provide an integer between 1 and 128\n");
}
break;

case 'b':
Expand Down

0 comments on commit 0fe0502

Please sign in to comment.