Skip to content
This repository was archived by the owner on Aug 22, 2019. It is now read-only.
This repository was archived by the owner on Aug 22, 2019. It is now read-only.

Inbalanced yy_preproc -> current_file Stack #23

@zhanghongce

Description

@zhanghongce

Hi, again!

I think there might be an issue with the yy_preproc -> current_file stack when handling preprocessor macros (but not the include). For MACRO_IDENTIFIER, the lexer will jump into the macro definitions, but unlike the way that "include" is handled, it does not push the stack. At the end of that string, it will trigger the <<EOF>> case, which pops the stack. This could cause stack underflow, and when later yy_preproc -> current_file is used to assigned to the meta field, the file name there becomes null (the stack returns null when is underflowed.)

{MACRO_IDENTIFIER}     {

    // Look for the macro entry.
    verilog_macro_directive * macro = NULL;
    char * macroName = (yytext)+1;
    ast_hashtable_result r = ast_hashtable_get(yy_preproc -> macrodefines,
                                               macroName,
                                               (void**)&macro);
    
    if(r == HASH_SUCCESS)
    {
        // Switch buffers to expand the macro.

        YY_BUFFER_STATE cur = YY_CURRENT_BUFFER;
        YY_BUFFER_STATE n   = yy_scan_string(macro -> macro_value);
        
        yy_switch_to_buffer(cur);
        yypush_buffer_state(n);
    }
    else
    {
        // Undefined macro - PANIC!
        //printf("ERROR: Undefined macro '%s' on line %d\n", yytext, yylineno);
        //printf("\tIt's probably all going to fall apart now...\n\n");
    }
}
<<EOF>> {

    yypop_buffer_state();

    // We are exiting a file, so pop from the the preprocessor stack of files
    // being parsed.
    ast_stack_pop(yy_preproc -> current_file);


    if ( !YY_CURRENT_BUFFER )
    {
        yyterminate();
    }
    else
    {
        YY_BUFFER_STATE cur = YY_CURRENT_BUFFER;
        yylineno = cur -> yy_bs_lineno;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions