Advertisement Jump to content
Sign in to follow this  
Jason Goepel

asCTokenizer::IsComment

This topic is 1752 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

The following code checks for a one-line comment.

 

as_tokenizer.cpp(213):

if( source[1] == '/' )
{
    // One-line comment

    // Find the length
    size_t n;
    for( n = 2; n < sourceLength; n++ )
    {
        if( source[n] == '\n' )
            break;
    }

    tokenType   = ttOnelineComment;
    tokenLength = n+1;

    return true;
}

Of the last part of "source" is a comment such that the for loop breaks when n == sourceLength (instead of finding a line feed character), tokenLength gets assigned a value one greater than sourceLength.

 

It seems incorrect that the returned "tokenLength" should exceed the "sourceLength".

 

Share this post


Link to post
Share on other sites
Advertisement

I had written some preprocessing/intellisense code.  One of my functions "SkipCommentsAndWhitespace" sometimes would crash when the source ended in a single-line comment.  The pointer to the source was increased passed the end of the source (as a result of adding a length returned from the asIScriptEngine::ParseToken function).  I'll admit, it took me a little while to track it down smile.png

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!