Fixed a bug where insufficient operands would be reported where invalid input should be.

Fixed a bug where ee would crash if a negative factorial was specified.
This commit is contained in:
Jon-William Lewis
2016-08-18 21:27:38 -05:00
parent c59a4ebe2f
commit 2968740698

14
ee.h
View File

@@ -107,9 +107,11 @@ evaluate(STACK* target_stack, int operator){
break;
case '!' :
operands = getOperands(target_stack, 1);
if ((operands[0] != floor(operands[0])))
if ( (operands[0] != floor(operands[0])) || (operands[0] < 0))
{ ERR_INVALID_FACTORIAL = 1; }
else{
value = fact((int)operands[0]);
}
break;
default :
break;
@@ -151,14 +153,14 @@ reportErrors(){
* ERR_INVALID_INPUT.
*/
int errors = 0;
if (ERR_NS_OPERANDS){
printf("Error: insufficient operands.\n"); errors++;
if (ERR_INVALID_INPUT){
printf("Error: Unexpected input.\n"); errors++;
} else if (ERR_NS_OPERATORS){
printf("Error: insufficient operators.\n"); errors++;
} else if (ERR_INVALID_INPUT){
printf("Error: Unexpected input.\n"); errors++;
} else if (ERR_NS_OPERANDS){
printf("Error: insufficient operands.\n"); errors++;
} else if (ERR_INVALID_FACTORIAL){
printf("Error: only integer factorials are supported.\n"); errors++;
printf("Error: Factorials are only supported for positive integers.\n"); errors++;
}
return errors;
}