diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-03-22 13:11:14 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-03-22 13:16:24 +0200 |
commit | 03b7314673fc4030e933f86890aad7f82ec30eca (patch) | |
tree | 0e9e00ce9cfc5a52a2ff21c06f800b7b9879a22a | |
parent | f91b19e696794204f2ba05587eb0dc0475c65345 (diff) | |
download | cflow-03b7314673fc4030e933f86890aad7f82ec30eca.tar.gz cflow-03b7314673fc4030e933f86890aad7f82ec30eca.tar.bz2 |
Properly handle invalid input
See https://savannah.gnu.org/bugs/?44113
* src/parser.c (cleanup_stack): Ignore negative deltas.
(parse_function_declaration): Don't set caller if the symbol
is in automatic storage. Note: that means nested function definitions
can't be handled.
* tests/invalid.at: New test case.
* tests/Makefile.am: Add new test case.
* tests/testsuite.at: Likewise.
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | src/parser.c | 7 | ||||
-rw-r--r-- | tests/Makefile.am | 1 | ||||
-rw-r--r-- | tests/invalid.at | 34 | ||||
-rw-r--r-- | tests/testsuite.at | 1 |
5 files changed, 42 insertions, 2 deletions
@@ -15,2 +15,3 @@ ChangeLog INSTALL +TAGS Makefile diff --git a/src/parser.c b/src/parser.c index 4126145..4be9d4e 100644 --- a/src/parser.c +++ b/src/parser.c @@ -276,5 +276,6 @@ cleanup_stack() - if (delta) + if (delta > 0) memmove(token_stack, token_stack+curs, delta*sizeof(token_stack[0])); - + else if (delta < 0) /* Invalid input */ + delta = 0; tos = delta; @@ -654,2 +655,4 @@ parse_function_declaration(Ident *ident, int parm) caller = lookup(ident->name); + if (caller && caller->storage == AutoStorage) + caller = NULL; func_body(); diff --git a/tests/Makefile.am b/tests/Makefile.am index 5f7d77c..4173c5f 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -50,2 +50,3 @@ TESTSUITE_AT = \ include.at\ + invalid.at\ knr.at\ diff --git a/tests/invalid.at b/tests/invalid.at new file mode 100644 index 0000000..581f8eb --- /dev/null +++ b/tests/invalid.at @@ -0,0 +1,34 @@ +# This file is part of GNU cflow testsuite. -*- Autotest -*- +# Copyright (C) 2016 Sergey Poznyakoff +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 3, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +AT_SETUP([invalid input]) +AT_KEYWORDS([invalid]) + +# See https://savannah.gnu.org/bugs/?44113 +CFLOW_CHECK([ +m{int +r(a(n){}e +]) + +CFLOW_CHECK([ +e(S,t)e(S{ +]) + +CFLOW_CHECK([ +n{void y(r(i){}a +]) + +AT_CLEANUP diff --git a/tests/testsuite.at b/tests/testsuite.at index e516a78..7ed3d7a 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -73,2 +73,3 @@ m4_include([struct04.at]) m4_include([decl01.at]) +m4_include([invalid.at]) |