[antlr-interest] [C] reuse() bug here?

Ruslan Zasukhin ruslan_zasukhin at valentina-db.com
Fri Nov 18 07:12:01 PST 2011


Hi Jim,

I think bug is here ... Just only have found this place during debug,
And need run away for few hours.


static pANTLR3_COMMON_TOKEN
newPoolToken(pANTLR3_TOKEN_FACTORY factory)
{
    pANTLR3_COMMON_TOKEN token;

    /* See if we need a new token pool before allocating a new
     * one
     */
    if (factory->nextToken >= ANTLR3_FACTORY_POOL_SIZE)
<<<<<<<<<<<<<< 1 !! If we have FEW pools then this is wrong.
    {
        /* We ran out of tokens in the current pool, so we need a new pool
         */
        newPool(factory);
    }

    /* Assuming everything went well (we are trying for performance here so
doing minimal
     * error checking. Then we can work out what the pointer is to the next
token.
     */

    token = factory->pools[factory->thisPool] + factory->nextToken;
                                           ^^^^^^^^^^^^^^^^^^^^^^
                                      // RZ: nextToken was 1024, we have
allocate above new pool
                                      // and we should use its ZERO item

    factory->nextToken++;             // and we get 1025 ...


It seems to me ... We must nextToken counter drop to zero when we allocate
next pool.

And may be correct other places ...


-- 
Best regards,

Ruslan Zasukhin
VP Engineering and New Technology
Paradigma Software, Inc

Valentina - Joining Worlds of Information
http://www.paradigmasoft.com

[I feel the need: the need for speed]



More information about the antlr-interest mailing list