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:
while (*(--p) <= _T(' ') && p > buffer)
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:
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);
The attached patch is the same as above, but with abuild-fix and a correction of slashes in the unix project-file.