summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2016-03-22 11:11:14 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2016-03-22 11:16:24 (GMT)
commit03b7314673fc4030e933f86890aad7f82ec30eca (patch) (side-by-side diff)
tree0e9e00ce9cfc5a52a2ff21c06f800b7b9879a22a
parentf91b19e696794204f2ba05587eb0dc0475c65345 (diff)
downloadcflow-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.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--.gitignore1
-rw-r--r--src/parser.c7
-rw-r--r--tests/Makefile.am1
-rw-r--r--tests/invalid.at34
-rw-r--r--tests/testsuite.at1
5 files changed, 42 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index 60d871e..9039854 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,6 +13,7 @@
ABOUT-NLS
ChangeLog
INSTALL
+TAGS
Makefile
Makefile.in
aclocal.m4
diff --git a/src/parser.c b/src/parser.c
index 4126145..4be9d4e 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -274,9 +274,10 @@ cleanup_stack()
{
int delta = tos - curs;
- 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;
curs = 0;
}
@@ -652,6 +653,8 @@ parse_function_declaration(Ident *ident, int parm)
case LBRACE:
if (ident->name) {
caller = lookup(ident->name);
+ if (caller && caller->storage == AutoStorage)
+ caller = NULL;
func_body();
}
break;
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 5f7d77c..4173c5f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -48,6 +48,7 @@ TESTSUITE_AT = \
funcarg.at\
hiding.at\
include.at\
+ invalid.at\
knr.at\
multi.at\
nfarg.at\
diff --git a/tests/invalid.at b/tests/invalid.at
new file mode 100644
index 0000000..581f8eb
--- a/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
@@ -71,5 +71,6 @@ m4_include([struct02.at])
m4_include([struct03.at])
m4_include([struct04.at])
m4_include([decl01.at])
+m4_include([invalid.at])
# End of testsuite.at

Return to:

Send suggestions and report system problems to the System administrator.