From 2d8d66094503abb2e5d43ba788c2373655f8d8a3 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Tue, 23 Feb 2016 12:26:47 +0100 Subject: [PATCH 1/2] fix crash with templates containing shifts --- c.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/c.c b/c.c index 40db0e5..b3296ec 100644 --- a/c.c +++ b/c.c @@ -1388,10 +1388,16 @@ static void skipToMatch (const char *const pair) { if (CollectingSignature) vStringPut (Signature, c); - if (c == begin) { + char s = cppGetc(); + if (s == '<' && s == c) { + // templates can still contain "<<" ot "<<=" + break; + } else { + cppUngetc(s); + } ++matchLevel; if (braceFormatting && getDirectiveNestLevel () != initialLevel) { From eb6204ba288f3f2e0151020eccba64544d672bc0 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Tue, 23 Feb 2016 12:58:40 +0100 Subject: [PATCH 2/2] C++: mitigate matching error on generics containing an expression backport of https://github.com/geany/geany/commit/d40932ce4d05e57573a6d6c8f89f4aea8c42d4f3 --- c.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/c.c b/c.c index b3296ec..0778620 100644 --- a/c.c +++ b/c.c @@ -1414,6 +1414,16 @@ static void skipToMatch (const char *const pair) break; } } + /* early out if matching "<>" and we encounter a ";" or "{" to mitigate + * match problems with C++ generics containing a static expression like + * foo bar; + * normally neither ";" nor "{" could appear inside "<>" anyway. */ + else if (isLanguage (Lang_cpp) && begin == '<' && + (c == ';' || c == '{')) + { + cppUngetc (c); + break; + } } if (c == EOF) {