Fix floating point division by zero in preprocessor expressions.
Closes #1183
This commit is contained in:
parent
07a30249f4
commit
ea5b55ecf4
4 changed files with 39 additions and 4 deletions
|
|
@ -7,6 +7,10 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
|
|||
Version 4.0.0 (in progress)
|
||||
===========================
|
||||
|
||||
2018-01-15: wsfulton
|
||||
Fix issue #1183. Floating point exception evaluating preprocessor expressions
|
||||
resulting in division by zero.
|
||||
|
||||
2018-01-14: wsfulton
|
||||
Fix issue #1172. Seg fault parsing invalid exponents in the preprocessor.
|
||||
|
||||
|
|
|
|||
13
Examples/test-suite/errors/pp_expressions_bad.i
Normal file
13
Examples/test-suite/errors/pp_expressions_bad.i
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
%module xxx
|
||||
|
||||
#define ZERO 0
|
||||
|
||||
#if 1%ZERO
|
||||
#endif
|
||||
#if 2/ZERO
|
||||
#endif
|
||||
|
||||
#if 1%(5-5)
|
||||
#endif
|
||||
#if 2/(55-55)
|
||||
#endif
|
||||
8
Examples/test-suite/errors/pp_expressions_bad.stderr
Normal file
8
Examples/test-suite/errors/pp_expressions_bad.stderr
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
pp_expressions_bad.i:5: Warning 202: Could not evaluate expression '1%ZERO'
|
||||
pp_expressions_bad.i:5: Warning 202: Error: 'Modulo by zero in expression'
|
||||
pp_expressions_bad.i:7: Warning 202: Could not evaluate expression '2/ZERO'
|
||||
pp_expressions_bad.i:7: Warning 202: Error: 'Division by zero in expression'
|
||||
pp_expressions_bad.i:10: Warning 202: Could not evaluate expression '1%(5-5)'
|
||||
pp_expressions_bad.i:10: Warning 202: Error: 'Modulo by zero in expression'
|
||||
pp_expressions_bad.i:12: Warning 202: Could not evaluate expression '2/(55-55)'
|
||||
pp_expressions_bad.i:12: Warning 202: Error: 'Division by zero in expression'
|
||||
|
|
@ -188,12 +188,22 @@ static int reduce_op() {
|
|||
sp--;
|
||||
break;
|
||||
case SWIG_TOKEN_SLASH:
|
||||
stack[sp - 2].value = stack[sp - 2].value / stack[sp].value;
|
||||
sp -= 2;
|
||||
if (stack[sp].value != 0) {
|
||||
stack[sp - 2].value = stack[sp - 2].value / stack[sp].value;
|
||||
sp -= 2;
|
||||
} else {
|
||||
errmsg = "Division by zero in expression";
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case SWIG_TOKEN_PERCENT:
|
||||
stack[sp - 2].value = stack[sp - 2].value % stack[sp].value;
|
||||
sp -= 2;
|
||||
if (stack[sp].value != 0) {
|
||||
stack[sp - 2].value = stack[sp - 2].value % stack[sp].value;
|
||||
sp -= 2;
|
||||
} else {
|
||||
errmsg = "Modulo by zero in expression";
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case SWIG_TOKEN_LSHIFT:
|
||||
stack[sp - 2].value = stack[sp - 2].value << stack[sp].value;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue