Modified parse_int_arg to better handle too-large and too-small associativities.
This commit is contained in:
parent
f018d83848
commit
df84d11ffb
15
csim.c
15
csim.c
@ -208,14 +208,25 @@ long parse_int_arg(char* arg, char opt)
|
|||||||
char* end;
|
char* end;
|
||||||
long i = strtol(arg, &end, 0);
|
long i = strtol(arg, &end, 0);
|
||||||
|
|
||||||
if (*end != '\0' || (!i && opt=='E')) { // associativity can not be zero
|
if (*end != '\0') { // associativity can not be zero
|
||||||
printf("Invalid argument \"%s\" for option -%c\n", arg, opt);
|
printf("Invalid argument \"%s\" for option -%c\n", arg, opt);
|
||||||
bad_usage_error();
|
bad_usage_error();
|
||||||
}
|
}
|
||||||
else if (i < 0) {
|
else if (i < 0) {
|
||||||
printf("Argument %ld for option %c too small (must be greater than 0)", i, opt);
|
printf("Argument %s for option -%c too small (must be greater than 0)", arg, opt);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
else if (opt == 'E') {
|
||||||
|
long long_max = (~0UL)>>1;
|
||||||
|
if (i==0) {
|
||||||
|
printf("Argument for option -E can not be 0\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
else if (i == long_max) {
|
||||||
|
printf("Argument %s for option -E too large (must be less than %ld)\n", arg, long_max);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user