Developer forums (C::B DEVELOPMENT STRICTLY!) > CodeCompletion redesign

A bug in handling #define

(1/3) > >>

ollydbg:
For example, when parsing this statement:

--- Code: ---#define _NO_DEBUG_PLACEHOLDER _No_debug_placeholder = _No_debug_placeholder()
--- End code ---

See the source code in parserthread.cpp

--- Code: ---void ParserThread::HandleDefines()
{
    wxString filename;
    int lineNr = m_Tokenizer.GetLineNumber();
    wxString token = m_Tokenizer.GetToken(); // read the token after #define
    m_Str.Clear();
    // now token holds something like:
    // BLAH_BLAH
    if (!token.IsEmpty())
    {
        // skip the rest of the #define
        wxString defVal = token + m_Tokenizer.ReadToEOL();
        wxString para(_T(""));
        int start = defVal.Find('(');
        int end   = defVal.Find(')');

        TRACE(_T("HandleDefines() : Saving nesting level: %d,%d"), start, end);

        // make sure preprocessor definitions are not going under namespaces or classes!
        if (start != wxNOT_FOUND && end != wxNOT_FOUND)
        {
            para = defVal.Mid(start, end-start+1);
            m_Str = defVal.Mid(end + 1);
            m_Str.Trim(false);
        }
        else
        {
            m_Str = defVal.substr(token.length());
            m_Str.Trim(false);
            //defVal = _T("");
        }
        Token* oldParent = m_pLastParent;
        m_pLastParent = 0L;
        DoAddToken(tkPreprocessor, token, lineNr, lineNr, m_Tokenizer.GetLineNumber(), para, false, true);
        m_pLastParent = oldParent;
        m_Str.Clear();
    }
}
--- End code ---

The "()" at the end of the line was mistakenly regarded as the "parameter" of the define, like below:

--- Code: ---#define _NO_DEBUG_PLACEHOLDER() XXXXXX
--- End code ---

blueshake:
Patch for it:

ollydbg:
thank you.now, i'm at home and view this forum in my gphone. i will test it when i am at work.
Happy Chinese New Year to every fourmers!

blueshake:
it is better to replace

--- Code: ---m_Str << m_Tokenizer.ReadToEOL();
--- End code ---

with

--- Code: ---if (!m_Str.IsEmpty())
    m_Str << _T(" ") <<  m_Tokenizer.ReadToEOL();
--- End code ---

we need a space between two word here.

MortenMacFly:

--- Quote from: blueshake on February 18, 2010, 07:59:30 am ---
--- Code: ---if (!m_Str.IsEmpty())
    m_Str << _T(" ") <<  m_Tokenizer.ReadToEOL();
--- End code ---
we need a space between two word here.

--- End quote ---
Are you sure? Because in the case m_Str.IsEmpty(), m_Tokenizer.ReadToEOL() is not being called. Didn't you mean something like:

--- Code: ---if (!m_Str.IsEmpty())
    m_Str << _T(" "):
m_Str << m_Tokenizer.ReadToEOL();

--- End code ---
???

Navigation

[0] Message Index

[#] Next page

Go to full version