Developer forums (C::B DEVELOPMENT STRICTLY!) > Development
A bug at CodeCompletion::NativeParser
lights_joy:
here is a code fragment at codecompletion/nativeparser.cpp
unsigned int NativeParser::FindCCTokenStart(const wxString& line)
{
int x = line.Length() - 1;
int nest = 0;
bool repeat = true;
while (repeat)
{
repeat = false;
while (x >= 0 && (wxIsalnum(line.GetChar(x)) || line.GetChar(x) == '_'))
--x;
if (x > 0 &&
(line.GetChar(x) == '>' && line.GetChar(x - 1) == '-') ||
(line.GetChar(x) == ':' && line.GetChar(x - 1) == ':'))
{
x -= 2;
repeat = true;
}
................
}
this judgement:
(line.GetChar(x) == ':' && line.GetChar(x - 1) == ':')
will execute everytime but sometimes x will be -1, so it will disp an assert dialog.
is it a bug?
Jenna:
The line will also only be executed if x is greater 0 and not everytime.
If the first condition in a "&&" statement is "false" no other condition gets tested.
The same is for "||": if the first condition is true no other condition will be tested.
MortenMacFly:
--- Quote from: jens on September 13, 2008, 10:21:33 am ---If the first condition in a "&&" statement is "false" no other condition gets tested.
--- End quote ---
Depends a bit on the compiler, but all recent ones do exactly like that. Especially the version of MinGW/GCC we are using.
lights_joy:
i know this rule. the raw code equal to:
if ((x > 0 &&
(line.GetChar(x) == '>' && line.GetChar(x - 1) == '-')) ||
(line.GetChar(x) == ':' && line.GetChar(x - 1) == ':'))
if x <= 0
the first judgement x > 0 will be false, so the second judgement will not be executed. now the first two condition get false, but the second operator is ||, so the third judgement will be executed.
I compile codeblock under vs2005, it fails sometimes.
so i think it's better to be
if (x > 0 &&
((line.GetChar(x) == '>' && line.GetChar(x - 1) == '-') ||
(line.GetChar(x) == ':' && line.GetChar(x - 1) == ':')))
killerbot:
I should check my special versions of these files, but I seem to remember GCC 4.3 also complains about this CORRECTLY.
And your suggestion is also what I have come up with since the parser wants (at least that's what I think was the purpose) :
X > 0 (meaning x-1 can be 0 but for sure not negative) and we want to check if it is : -> or ::
Navigation
[0] Message Index
[#] Next page
Go to full version