[antlr-interest] [C] Crashes if NULL name in antlr3StringStreamNew()

Ruslan Zasukhin ruslan_zasukhin at valentina-db.com
Tue Aug 30 23:35:00 PDT 2011


On 8/30/11 4:17 PM, "Ruslan Zasukhin" <ruslan_zasukhin at valentina-db.com>
wrote:

> 
> If I call
> 
>     input = antlr3StringStreamNew(
>         input_string, Encoding, input_len, NULL );
>             
> NULL is name of stream
> Then it crashes inside of
> 
> 
> newStr8    (pANTLR3_STRING_FACTORY factory, pANTLR3_UINT8 ptr)
> {
>     return factory->newPtr8(factory, ptr,
>          (ANTLR3_UINT32)strlen((const char *)ptr));        <<<<<< crash
> }
> 
> 
> Because on mac and linux strlen()  crashes on NULL.

In contrast to above, new  reuse() method can handle stream name as NULL,
Replacing to ³-memory-² name.


========================================================
antlr38BitReuse(pANTLR3_INPUT_STREAM input, pANTLR3_UINT8 inString,
ANTLR3_UINT32 size, pANTLR3_UINT8 name)
{
    input->isAllocated    = ANTLR3_FALSE;
    input->data        = inString;
    input->sizeBuf    = size;
    
    // Now we can set up the file name. As we are reusing the stream, there
may already
    // be a string that we can reuse for holding the filename.
    //
    if    (input->istream->streamName == NULL)
    {
        input->istream->streamName    =
input->strFactory->newStr(input->strFactory, name == NULL ?
(pANTLR3_UINT8)"-memory-" : name);
        input->fileName        = input->istream->streamName;
    }
    else
    {
        input->istream->streamName->set(input->istream->streamName,  (name
== NULL ? (const char *)"-memory-" : (const char *)name));
    }

    input->reset(input);
}



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