Author Topic: A bug at CodeCompletion::NativeParser  (Read 11601 times)

Offline lights_joy

  • Multiple posting newcomer
  • *
  • Posts: 13
A bug at CodeCompletion::NativeParser
« on: September 13, 2008, 09:35:51 am »
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?

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: A bug at CodeCompletion::NativeParser
« Reply #1 on: September 13, 2008, 10:21:33 am »
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.
« Last Edit: September 13, 2008, 10:36:58 am by jens »

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: A bug at CodeCompletion::NativeParser
« Reply #2 on: September 13, 2008, 01:10:05 pm »
If the first condition in a "&&" statement is "false" no other condition gets tested.
Depends a bit on the compiler, but all recent ones do exactly like that. Especially the version of MinGW/GCC we are using.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline lights_joy

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: A bug at CodeCompletion::NativeParser
« Reply #3 on: September 13, 2008, 03:05:39 pm »
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) == ':'))
)

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5506
Re: A bug at CodeCompletion::NativeParser
« Reply #4 on: September 13, 2008, 03:26:51 pm »
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 ::
« Last Edit: September 13, 2008, 03:28:52 pm by killerbot »

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: A bug at CodeCompletion::NativeParser
« Reply #5 on: September 13, 2008, 04:41:22 pm »
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) == ':'))
)

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 ::

You are right, this seems to be a bug.
... and we should have a close look on similar constructs gcc-4.3 warns about.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: A bug at CodeCompletion::NativeParser
« Reply #6 on: September 14, 2008, 02:38:11 pm »
You are right, this seems to be a bug.
Woot. I did not check the third condition but it seems right...?! :shock:

... and we should have a close look on similar constructs gcc-4.3 warns about.
Indeed. Who's using this compiler already to compile C::B? Could anyone provide a compiler log (e.g. the one C::B produces) for the C::B project and the (contrib) plugins with the appropriate warning level enabled?

Mmmmh... Probably now it's time to install the TDragon stuff once again...
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Online stahta01

  • Lives here!
  • ****
  • Posts: 7625
    • My Best Post
Re: A bug at CodeCompletion::NativeParser
« Reply #7 on: September 14, 2008, 05:10:12 pm »
Indeed. Who's using this compiler already to compile C::B? Could anyone provide a compiler log (e.g. the one C::B produces) for the C::B project and the (contrib) plugins with the appropriate warning level enabled?

I have TDM MinGW Installed; what is the appropriate warning level?

Tim S
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: A bug at CodeCompletion::NativeParser
« Reply #8 on: September 14, 2008, 05:37:23 pm »
I have TDM MinGW Installed; what is the appropriate warning level?
I don't really know. Just try -W and -Wall together. This should most likely include everything. ;-)
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Online stahta01

  • Lives here!
  • ****
  • Posts: 7625
    • My Best Post
Re: A bug at CodeCompletion::NativeParser
« Reply #9 on: September 14, 2008, 05:51:55 pm »
I have TDM MinGW Installed; what is the appropriate warning level?
I don't really know. Just try -W and -Wall together. This should most likely include everything. ;-)

Ok; will do with those options.

Having to recompile wxWidgets, using 4.3.2, an ABI looking error happens.

Note: I think an wxWidgets complied with 4.3.2 can work with Code::Blocks compiled with 3.4.5.
But, wxWidgets complied with 3.4.5 does NOT work with Code::Blocks compiled with 4.3.2.

Edit: -W gave way too many warnings; removed it.

Trying with -Wall and -Wmissing-include-dirs

Code
||=== Code::Blocks, tinyXML ===|
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\base\tinyxml\tinyxmlparser.cpp|357|warning: suggest parentheses around && within |||
||=== Code::Blocks, Squirrel ===|
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\scripting\squirrel\sqapi.cpp||In function 'SQRESULT sq_rawdeleteslot(SQVM*, SQInteger, SQBool)':|
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\scripting\squirrel\sqapi.cpp|764|warning: suggest explicit braces to avoid ambiguous 'else'|
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\scripting\squirrel\sqcompiler.cpp||In member function 'void SQCompiler::ParseTableOrClass(SQInteger, SQInteger)':|
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\scripting\squirrel\sqcompiler.cpp|781|warning: suggest parentheses around && within |||
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\scripting\squirrel\sqvm.cpp||In member function 'bool SQVM::IsFalse(SQObjectPtr&)':|
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\scripting\squirrel\sqvm.cpp|647|warning: suggest parentheses around && within |||
||=== Code::Blocks, Squirrel std lib ===|
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\scripting\sqstdlib\sqstdrex.cpp||In function 'const SQChar* sqstd_rex_matchnode(SQRex*, SQRexNode*, const SQChar*, SQRexNode*)':|
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\scripting\sqstdlib\sqstdrex.cpp|487|warning: suggest parentheses around && within |||
||=== Code::Blocks, scintilla ===|
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\wxscintilla\src\ScintillaWX.cpp||In member function 'bool ScintillaWX::HasCaretSizeChanged()':|
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\wxscintilla\src\ScintillaWX.cpp|677|warning: suggest parentheses around && within |||
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\wxscintilla\src\scintilla\src\Document.cxx||In member function 'long int Document::FindText(int, int, const char*, bool, bool, bool, bool, bool, int*)':|
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\wxscintilla\src\scintilla\src\Document.cxx|1129|warning: suggest parentheses around && within |||
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\wxscintilla\src\scintilla\src\Document.cxx|1130|warning: suggest parentheses around && within |||
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\wxscintilla\src\scintilla\src\Document.cxx|1145|warning: suggest parentheses around && within |||
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\wxscintilla\src\scintilla\src\Document.cxx|1146|warning: suggest parentheses around && within |||
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\wxscintilla\src\scintilla\src\Editor.cxx||In member function 'void Editor::LayoutLine(int, Surface*, ViewStyle&, LineLayout*, int)':|
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\wxscintilla\src\scintilla\src\Editor.cxx|2060|warning: array subscript has type 'char'|
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\wxscintilla\src\scintilla\src\Editor.cxx|2063|warning: array subscript has type 'char'|
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\wxscintilla\src\scintilla\src\Editor.cxx|2066|warning: array subscript has type 'char'|
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\wxscintilla\src\scintilla\src\LexFortran.cxx||In function 'void ColouriseFortranDoc(unsigned int, int, int, WordList**, Accessor&, bool)':|
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\wxscintilla\src\scintilla\src\LexFortran.cxx|81|warning: suggest parentheses around && within |||
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\wxscintilla\src\scintilla\src\LexFortran.cxx||In function 'int classifyFoldPointFortran(const char*, const char*, char)':|
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\wxscintilla\src\scintilla\src\LexFortran.cxx|242|warning: suggest parentheses around && within |||
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\wxscintilla\src\scintilla\src\LexInno.cxx||In function 'void FoldInnoDoc(unsigned int, int, int, WordList**, Accessor&)':|
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\wxscintilla\src\scintilla\src\LexInno.cxx|287|warning: suggest parentheses around arithmetic in operand of ||
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\wxscintilla\src\scintilla\src\LexOthers.cxx||In function 'void FoldPropsDoc(unsigned int, int, int, WordList**, Accessor&)':|
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\wxscintilla\src\scintilla\src\LexOthers.cxx|709|warning: suggest parentheses around arithmetic in operand of ||
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\wxscintilla\src\scintilla\src\LexPython.cxx||In function 'void ColourisePyDoc(unsigned int, int, int, WordList**, Accessor&)':|
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\wxscintilla\src\scintilla\src\LexPython.cxx|268|warning: suggest parentheses around && within |||
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\wxscintilla\src\scintilla\src\LexRuby.cxx||In function 'void ColouriseRbDoc(unsigned int, int, int, WordList**, Accessor&)':|
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\wxscintilla\src\scintilla\src\LexRuby.cxx|708|warning: suggest parentheses around && within |||
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\wxscintilla\src\scintilla\src\LexTADS3.cxx||In function 'bool IsStringTransition(int, int)':|
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\wxscintilla\src\scintilla\src\LexTADS3.cxx|619|warning: suggest parentheses around && within |||
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\wxscintilla\src\scintilla\src\LexVerilog.cxx||In function 'void FoldNoBoxVerilogDoc(unsigned int, int, int, Accessor&)':|
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\wxscintilla\src\scintilla\src\LexVerilog.cxx|246|warning: suggest parentheses around && within |||
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\wxscintilla\src\scintilla\src\LexVerilog.cxx|256|warning: suggest parentheses around && within |||
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\wxscintilla\src\scintilla\src\LexVerilog.cxx|257|warning: suggest parentheses around && within |||
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\wxscintilla\src\scintilla\src\RESearch.cxx||In member function 'const char* RESearch::Compile(const char*, int, bool, bool)':|
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\wxscintilla\src\scintilla\src\RESearch.cxx|309|warning: suggest explicit braces to avoid ambiguous 'else'|
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\wxscintilla\src\scintilla\src\RESearch.cxx||In member function 'int RESearch::PMatch(CharacterIndexer&, int, int, char*)':|
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\wxscintilla\src\scintilla\src\RESearch.cxx|679|warning: array subscript has type 'char'|
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\wxscintilla\src\scintilla\src\RESearch.cxx|682|warning: array subscript has type 'char'|
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\wxscintilla\src\scintilla\src\RESearch.cxx|685|warning: suggest parentheses around && within |||
||=== Code::Blocks, sdk ===|
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\cbproject.cpp||In constructor 'cbProject::cbProject(const wxString&)':|
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\sdk\cbproject.cpp|72|warning: suggest parentheses around && within |||
||=== Code::Blocks, Debugger ===|
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\plugins\debuggergdb\gdb_driver.cpp||In member function 'virtual void GDB_driver::ParseOutput(const wxString&)':|
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\plugins\debuggergdb\gdb_driver.cpp|788|warning: suggest parentheses around && within |||
||=== Code::Blocks, Code-completion ===|
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\plugins\codecompletion\classbrowserbuilderthread.cpp||In member function 'wxTreeItemId ClassBrowserBuilderThread::AddNodeIfNotThere(wxTreeCtrl*, wxTreeItemId, const wxString&, int, CBTreeData*, bool)':|
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\plugins\codecompletion\classbrowserbuilderthread.cpp|365|warning: suggest parentheses around comparison in operand of &|
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\plugins\codecompletion\nativeparser.cpp||In member function 'unsigned int NativeParser::FindCCTokenStart(const wxString&)':|
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\plugins\codecompletion\nativeparser.cpp|1139|warning: suggest parentheses around && within |||
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\plugins\codecompletion\parser\parserthread.cpp||In member function 'void ParserThread::DoParse()':|
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\plugins\codecompletion\parser\parserthread.cpp|660|warning: suggest parentheses around && within |||
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\plugins\codecompletion\parser\tokenizer.cpp||In member function 'bool Tokenizer::SkipUnwanted()':|
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\plugins\codecompletion\parser\tokenizer.cpp|403|warning: suggest parentheses around && within |||
||=== Code::Blocks, Projects-workspaces importer ===|
G:\SourceCode\Projects\IDEs\CodeBlocks\codeblocks\src\plugins\projectsimporter\msvcloader.cpp|686|warning: multi-line comment|
||=== Build finished: 0 errors, 34 warnings ===|

Tim S
« Last Edit: September 14, 2008, 07:10:53 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5506
Re: A bug at CodeCompletion::NativeParser
« Reply #10 on: September 14, 2008, 07:22:44 pm »
You are right, this seems to be a bug.
Woot. I did not check the third condition but it seems right...?! :shock:

... and we should have a close look on similar constructs gcc-4.3 warns about.
Indeed. Who's using this compiler already to compile C::B? Could anyone provide a compiler log (e.g. the one C::B produces) for the C::B project and the (contrib) plugins with the appropriate warning level enabled?

Mmmmh... Probably now it's time to install the TDragon stuff once again...

I did : I already reported this  : http://forums.codeblocks.org/index.php/topic,8659.0.html


The mentioned problem was even explained by me. But someone prefers to keep warnings and disregard them. So I didn't commit my fixes.
Now that some other people start to see the potential errors that can come from warnings, I will slowly apply my fixes ;-)

Can I ask to critically look at my commits, so that I don't screw up because otherwise someone is gonna coma after me ;-)

MY GOLDEN RULE : do it warning free. Compilers are *mostly* right. And the effort to keep things warning free is normally minimal, only when you let it slip ....

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: A bug at CodeCompletion::NativeParser
« Reply #11 on: September 15, 2008, 08:58:27 am »
Now that some other people start to see the potential errors that can come from warnings, I will slowly apply my fixes ;-)
Just do so. Go ahead. :D

Can I ask to critically look at my commits, so that I don't screw up because otherwise someone is gonna coma after me ;-)
...will do my very best... the others, too please. ;-)
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ