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:
14
ee.h
14
ee.h
@@ -107,9 +107,11 @@ evaluate(STACK* target_stack, int operator){
|
|||||||
break;
|
break;
|
||||||
case '!' :
|
case '!' :
|
||||||
operands = getOperands(target_stack, 1);
|
operands = getOperands(target_stack, 1);
|
||||||
if ((operands[0] != floor(operands[0])))
|
if ( (operands[0] != floor(operands[0])) || (operands[0] < 0))
|
||||||
{ ERR_INVALID_FACTORIAL = 1; }
|
{ ERR_INVALID_FACTORIAL = 1; }
|
||||||
|
else{
|
||||||
value = fact((int)operands[0]);
|
value = fact((int)operands[0]);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default :
|
default :
|
||||||
break;
|
break;
|
||||||
@@ -151,14 +153,14 @@ reportErrors(){
|
|||||||
* ERR_INVALID_INPUT.
|
* ERR_INVALID_INPUT.
|
||||||
*/
|
*/
|
||||||
int errors = 0;
|
int errors = 0;
|
||||||
if (ERR_NS_OPERANDS){
|
if (ERR_INVALID_INPUT){
|
||||||
printf("Error: insufficient operands.\n"); errors++;
|
printf("Error: Unexpected input.\n"); errors++;
|
||||||
} else if (ERR_NS_OPERATORS){
|
} else if (ERR_NS_OPERATORS){
|
||||||
printf("Error: insufficient operators.\n"); errors++;
|
printf("Error: insufficient operators.\n"); errors++;
|
||||||
} else if (ERR_INVALID_INPUT){
|
} else if (ERR_NS_OPERANDS){
|
||||||
printf("Error: Unexpected input.\n"); errors++;
|
printf("Error: insufficient operands.\n"); errors++;
|
||||||
} else if (ERR_INVALID_FACTORIAL){
|
} 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;
|
return errors;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user