Fix seg fault parsing invalid exponents

Add error message when exponents are incomplete,
for example 5e and 5.e
This commit is contained in:
William S Fulton 2018-01-14 19:36:09 +00:00
commit 07a30249f4
8 changed files with 36 additions and 6 deletions

View file

@ -7,6 +7,9 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
Version 4.0.0 (in progress) Version 4.0.0 (in progress)
=========================== ===========================
2018-01-14: wsfulton
Fix issue #1172. Seg fault parsing invalid exponents in the preprocessor.
2018-01-12: Liryna 2018-01-12: Liryna
[C#] Patch #1128. Add ToArray function to std::vector wrappers. [C#] Patch #1128. Add ToArray function to std::vector wrappers.

View file

@ -0,0 +1,4 @@
%module xxx
void bad(double nn = 5e);

View file

@ -0,0 +1,2 @@
cpp_invalid_exponents1.i:3: Error: Exponent does not have any digits
cpp_invalid_exponents1.i:3: Error: Syntax error in input(1).

View file

@ -0,0 +1,4 @@
%module xxx
void bad(double nn = 6.6e);

View file

@ -0,0 +1,2 @@
cpp_invalid_exponents2.i:3: Error: Exponent does not have any digits
cpp_invalid_exponents2.i:3: Error: Syntax error in input(1).

View file

@ -0,0 +1,7 @@
%module xxx
#if 123e
#endif
#if 456.e
#endif

View file

@ -0,0 +1,6 @@
:EOF: Error: Exponent does not have any digits
pp_invalid_exponents.i:3: Warning 202: Could not evaluate expression '123e'
pp_invalid_exponents.i:3: Warning 202: Error: 'Syntax error'
:EOF: Error: Exponent does not have any digits
pp_invalid_exponents.i:6: Warning 202: Could not evaluate expression '456.e'
pp_invalid_exponents.i:6: Warning 202: Error: 'Syntax error'

View file

@ -1118,27 +1118,29 @@ static int look(Scanner *s) {
break; break;
case 82: case 82:
if ((c = nextchar(s)) == 0) { if ((c = nextchar(s)) == 0) {
retract(s, 1); Swig_error(cparse_file, cparse_start_line, "Exponent does not have any digits\n");
return SWIG_TOKEN_INT; return SWIG_TOKEN_ERROR;
} }
if ((isdigit(c)) || (c == '-') || (c == '+')) if ((isdigit(c)) || (c == '-') || (c == '+'))
state = 86; state = 86;
else { else {
retract(s, 2); retract(s, 2);
return (SWIG_TOKEN_INT); Swig_error(cparse_file, cparse_start_line, "Exponent does not have any digits\n");
return SWIG_TOKEN_ERROR;
} }
break; break;
case 820: case 820:
/* Like case 82, but we've seen a decimal point. */ /* Like case 82, but we've seen a decimal point. */
if ((c = nextchar(s)) == 0) { if ((c = nextchar(s)) == 0) {
retract(s, 1); Swig_error(cparse_file, cparse_start_line, "Exponent does not have any digits\n");
return SWIG_TOKEN_DOUBLE; return SWIG_TOKEN_ERROR;
} }
if ((isdigit(c)) || (c == '-') || (c == '+')) if ((isdigit(c)) || (c == '-') || (c == '+'))
state = 86; state = 86;
else { else {
retract(s, 2); retract(s, 2);
return (SWIG_TOKEN_DOUBLE); Swig_error(cparse_file, cparse_start_line, "Exponent does not have any digits\n");
return SWIG_TOKEN_ERROR;
} }
break; break;
case 83: case 83: