diff --git a/csim.c b/csim.c index 4e37abe..fb00293 100644 --- a/csim.c +++ b/csim.c @@ -208,14 +208,25 @@ long parse_int_arg(char* arg, char opt) char* end; 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); bad_usage_error(); } 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); } + 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; }