Developer forums (C::B DEVELOPMENT STRICTLY!) > CodeCompletion redesign
cc-branch crashes on linux
Jenna:
The cc-branch crashes reproucible on linux, if <wx/hashmap.h> is parsed.
Ther crash happens in wxString Tokenizer::ReadToEOL(bool nestBraces, bool stripUnneeded) when #define _WX_DECLARE_HASHTABLE( [...] is parsed.
After many debugging I found the cause.
Normally if we reach the backslash before the EOL, the space(s) before the backslash and the backslash itself are removed from buffer by decrementing the pointer p and after that moving to the next char:
--- Code: ---while (*(--p) <= _T(' ') && p > buffer)
--- End code ---
In some rare cases we just appended the buffer to the return-string and set the temporary pointer p to the beginning of buffer. If we now decrement p and look if the character it points to is less or equal ' ' we get a segfault.
The same might happen some lines later.
This can only happen if the buffer is smaller than the line and if the next character (after appending buffer to str) is the backslash before the EOL.
I attach a project wher this happens (at least on linux 64-bit), I just copied the define of _WX_DECLARE_HASHTABLE into main.cpp and removed everything else.
The following patch avoids that problem, but it seems to change the behaviou alittle bit (for a simple hello-world project one file more is parsed, but less tokens are found).
Another approach would be to leave everything as it is, but do it only if p is greater than buffer and if it is not (buffer has already been appended to str), remove the trailing spaces from str.
It's also easy to do, but I am not sure whether it is needed, or if we can leave the spaces.
It would be nice if the cc-gurus can have alook at the patch:
--- Code: ---Index: src/plugins/codecompletion/parser/tokenizer.cpp
===================================================================
--- src/plugins/codecompletion/parser/tokenizer.cpp (Revision 6508)
+++ src/plugins/codecompletion/parser/tokenizer.cpp (Arbeitskopie)
@@ -410,13 +410,13 @@
break;
else
{
- while (*(--p) <= _T(' ') && p > buffer)
+ while ((p > buffer) && *(--p) <= _T(' '))
;
MoveToNextChar();
}
}
- while (*(p - 1) <= _T(' ') && --p > buffer)
+ while (p > buffer && *(--p) <= _T(' '))
;
str.Append(buffer, p - buffer);
--- End code ---
The attached patch is the same as above, but with abuild-fix and a correction of slashes in the unix project-file.
Loaden:
Thank Jens!
Loaden:
Hi, Jens, can you give me a favor?
In Ubuntu 10.04, if apply this patch, will lead C::B can not load libcodecompletion.so.
I check it more times, but i can not find the reason.
I need you help. ^_^
Loaden:
WOW, I got the reason.
THAT IS: We must add "classnavigator.cpp/h" to project!!
Solved now!
MortenMacFly:
--- Quote from: jens on August 22, 2010, 10:27:12 pm ---The following patch avoids that problem, but it seems to change the behaviou alittle bit (for a simple hello-world project one file more is parsed, but less tokens are found).
--- End quote ---
Ooops - sounds weired. You mean for a single file "Hello World" project?! :shock:
@Loaden: What could be the reason for this?!
Navigation
[0] Message Index
[#] Next page
Go to full version