Menu

cppcheck does not handle #line statements generated by Oracle ProC precompiler

2022-06-08
2022-06-20
  • Luis Cortes

    Luis Cortes - 2022-06-08

    Truthfully, it does sort of, ProC pre-compiler coverts C code that has embedded SQL into pure C code.

    The issue:

    This ProC process will create some structs and variables before all your code in a filename.c file. At the top of your code, but not the top of this new file.

    It is nice enough to set a #line 1 "orginalfname.sc" and it will do the same before/after sql statements because it is referencing the original file name.

    The problem:
    Occurs when cppcheck finds issue with the generated code that comes before all your code. Also, at times, it forgets the #line numbers and uses the absolute line numbers.

    Sample code:
    main.sc (with errors)
    main.c (generated)
    main.cppcheck (cppcheck results)

    Commands to generate:

    proc LINE=YES LTYPE=SHORT main.sc
    cppcheck main.c > main.cppcheck 2>&1     
    

    Ideally:
    I wouldn't mind the errors, but I would like to place a line at the top of the generated C file like so (manually is fine):

        #line 1 "main.pro-c-compiled.c"
    
    so that when I get errors, notes, warnings, I know where the errors are coming from, then it should "reset" when it hits the normal reference:
    
        #line 1 "main.sc"
    
    Right now, it is ignoring my statement:
    
    #line 1 "main.pro-c-compiled.c"
    

    and still says all errors, warnings, etc are found in main.sc

     

    Last edit: Luis Cortes 2022-06-08
  • Daniel Marjamäki

    Can you check what happens if you use gcc-compliant markers.

    Instead of:

     #line 1 "main.pro-c-compiled.c"
    

    I think it should say:

     # 1 "main.pro-c-compiled.c"
    
     
  • Luis Cortes

    Luis Cortes - 2022-06-20

    Tried it with cppcheck 2.8 and it still didn't work. It seems to ignore the directive at times and give you absolute line numbers. At other times, it seems like the "filename" given from the line directive is forgotten or it uses the wrong one.

     
  • Daniel Marjamäki

    I am not sure I understand exactly what you want but I do see that it does not work well.

     
  • Daniel Marjamäki

    The issue I can see:

    Reduced code:

    int main()
    {   
        char* ptr = 0;
    #line 16 "main.sc"
    
    #line 12 "main.sc"
        struct sqlexd sqlstm;
    
    #line 16 "main.sc"
        strcpy(ptr, "bad");
    }
    

    And the error that is written is:

    main.sc:21:12: error: Null pointer dereference: ptr [nullPointer]

    The line number should be 16.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.