From c28668eaddf956b8c481e436e939d0b35bacaf68 Mon Sep 17 00:00:00 2001 From: Wenji Huang Date: Tue, 12 Jan 2010 13:45:55 +0800 Subject: PR10747: check invalid preprocessor construct * parse.cxx (scan_pp): Match '%(' and '%?'. * testsuite/semko/conditional.stp: New test. --- parse.cxx | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'parse.cxx') diff --git a/parse.cxx b/parse.cxx index 55ec53fb..edb19275 100644 --- a/parse.cxx +++ b/parse.cxx @@ -380,6 +380,7 @@ parser::scan_pp (bool wildcard) vector my_enqueued_pp; int nesting = 0; + int then = 0; while (true) // consume THEN tokens { try @@ -394,11 +395,18 @@ parser::scan_pp (bool wildcard) if (m && m->type == tok_operator && m->content == "%(") // nested %( nesting ++; + if (m && m->type == tok_operator && m->content == "%?") { + then ++; + if (nesting != then) + throw parse_error ("incomplete conditional - missing '%('", m); + } if (nesting == 0 && m && (m->type == tok_operator && (m->content == "%:" || // ELSE m->content == "%)"))) // END break; - if (nesting && m && m->type == tok_operator && m->content == "%)") // nested %) + if (nesting && m && m->type == tok_operator && m->content == "%)") { // nested %) nesting --; + then --; + } if (!m) throw parse_error ("incomplete conditional - missing '%:' or '%)'", t); @@ -414,6 +422,7 @@ parser::scan_pp (bool wildcard) { delete m; // "%:" int nesting = 0; + int then = 0; while (true) { try @@ -428,10 +437,17 @@ parser::scan_pp (bool wildcard) if (m && m->type == tok_operator && m->content == "%(") // nested %( nesting ++; + if (m && m->type == tok_operator && m->content == "%?") { + then ++; + if (nesting != then) + throw parse_error ("incomplete conditional - missing '%('", m); + } if (nesting == 0 && m && m->type == tok_operator && m->content == "%)") // END break; - if (nesting && m && m->type == tok_operator && m->content == "%)") // nested %) + if (nesting && m && m->type == tok_operator && m->content == "%)") { // nested %) nesting --; + then --; + } if (!m) throw parse_error ("incomplete conditional - missing %)", t); -- cgit