Hi, thanks for the effort to build c::b, and it looks like you have build it successfully.
#6 0x00007fffc0b9e3b4 in Tokenizer::Lex (this=this@entry=0x7fffb01164d0) at parser/tokenizer.cpp:976
#7 0x00007fffc0ba20dc in Tokenizer::DoGetToken (this=this@entry=0x7fffb01164d0) at parser/tokenizer.cpp:936
#8 0x00007fffc0ba251f in Tokenizer::GetToken (this=this@entry=0x7fffb01164d0) at parser/tokenizer.cpp:843
#9 0x00007fffc0b8af79 in ParserThread::SkipToOneOfChars (this=this@entry=0x7fffb01164c0, chars=..., supportNesting=supportNesting@entry=false, singleCharToken=singleCharToken@entry=true) at parser/parserthread.cpp:238
#10 0x00007fffc0b949be in ParserThread::DoParse (this=this@entry=0x7fffb01164c0) at parser/parserthread.cpp:906
#11 0x00007fffc0b9833c in ParserThread::HandleClass (this=this@entry=0x7fffb01164c0, ct=ct@entry=ParserThread::ctStructure) at parser/parserthread.cpp:2114
#12 0x00007fffc0b948b3 in ParserThread::DoParse (this=this@entry=0x7fffb01164c0) at parser/parserthread.cpp:956
#13 0x00007fffc0b9833c in ParserThread::HandleClass (this=this@entry=0x7fffb01164c0, ct=ct@entry=ParserThread::ctStructure) at parser/parserthread.cpp:2114
#14 0x00007fffc0b948b3 in ParserThread::DoParse (this=this@entry=0x7fffb01164c0) at parser/parserthread.cpp:956
#15 0x00007fffc0b9833c in ParserThread::HandleClass (this=this@entry=0x7fffb01164c0, ct=ct@entry=ParserThread::ctStructure) at parser/parserthread.cpp:2114
#16 0x00007fffc0b948b3 in ParserThread::DoParse (this=this@entry=0x7fffb01164c0) at parser/parserthread.cpp:956
#17 0x00007fffc0b9833c in ParserThread::HandleClass (this=this@entry=0x7fffb01164c0, ct=ct@entry=ParserThread::ctStructure) at parser/parserthread.cpp:2114
#18 0x00007fffc0b948b3 in ParserThread::DoParse (this=this@entry=0x7fffb01164c0) at parser/parserthread.cpp:956
#19 0x00007fffc0b9833c in ParserThread::HandleClass (this=this@entry=0x7fffb01164c0, ct=ct@entry=ParserThread::ctStructure) at parser/parserthread.cpp:2114
...
This looks like an endless loop in the parser, so I need a way to reproduce this bug. Can you give me a minimal cbp project(with all the header files and source files in the project). Since I can't reproduce for a single source file.
OK, I correctly locate the bug, and please test this patch, I think it should fix the crash issue.
From 06b24abc0710e6befcbcbb18ad353aa8ae8a334f Mon Sep 17 00:00:00 2001
From: asmwarrior <asmwarrior@gmail.com>
Date: Wed, 7 Sep 2016 14:46:48 +0800
Subject: * CC: fix a endless loop crash bug when parsing C99 designated
initializer
Forum discussion is here:
http://forums.codeblocks.org/index.php/topic,21417.0.html
When parsing
struct AAA a1 = {.x = 1, .y=2}; // first line
struct AAA a2 = {.x = 1, .y=2}; // second line
When we see a "dot", we need to skip to "}", thus the close brace is
skipped, and the open brace is just start a function call of DoParse().
If we goes to the second line, we will call another DoParse(), so there
is recursive calls, and finally goes to crash.
Also, a cc test case is added
diff --git a/src/plugins/codecompletion/parser/parserthread.cpp b/src/plugins/codecompletion/parser/parserthread.cpp
index fc00985..3d81acf 100644
--- a/src/plugins/codecompletion/parser/parserthread.cpp
+++ b/src/plugins/codecompletion/parser/parserthread.cpp
@@ -2197,6 +2197,21 @@ void ParserThread::HandleClass(EClassType ct)
break;
}
// -------------------------------------------------------------------
+ else if(next == ParserConsts::equals)
+ // -------------------------------------------------------------------
+ {
+ // some patterns like: struct AAA a = {.x = 1, .y=2};
+ // In (ANSI) C99, you can use a designated initializer to initialize a structure
+ if (!lastCurrent.IsEmpty() )
+ {
+ m_Str << lastCurrent << ParserConsts::space_chr;
+ DoAddToken(tkVariable, current, m_Tokenizer.GetLineNumber());
+ }
+ // so we have to eat the brace pair
+ SkipToOneOfChars(ParserConsts::semicolon, /* supportNesting*/ true, /*singleCharToken*/ true);
+ break;
+ }
+ // -------------------------------------------------------------------
else
// -------------------------------------------------------------------
{
diff --git a/src/plugins/codecompletion/testing/cc_structs.cpp b/src/plugins/codecompletion/testing/cc_structs.cpp
new file mode 100644
index 0000000..82cd85a
--- /dev/null
+++ b/src/plugins/codecompletion/testing/cc_structs.cpp
@@ -0,0 +1,13 @@
+
+// parsing C99 designated initializer of struct
+// http://forums.codeblocks.org/index.php/topic,21417.0.html
+struct AAA
+{
+ int x;
+ float y;
+};
+
+struct AAA a1 = {.x = 1, .y=0.2}; // first line
+struct AAA a2 = {.x = 1, .y=0.2}; // second line
+
+//a //a1,a2
\ No newline at end of file