Menu

Warning found with GUI doesn't show in CLI

2020-10-14
2020-10-15
  • Julian Wörle

    Julian Wörle - 2020-10-14

    Hey everybody,

    I'm using cppcheck version 2.2

    I identified a warning with the cppcheck GUI in my program. When I use the the CLI to find the same warning, it doesn't show up.
    I can provide this small sample code:

    // file: test.c
    
    uint32_t test_func(uint32_t state)
    {
        uint32_t ret = 0;
    
        switch(state)
        {
            case 0:
                ret = 1;
            case 1:
                ret = 2;
                break;
            default:
                ret = 3;
                break;
        }
    
        return ret;
    }
    

    The GUI informs me with a warning about the missing break; after case 0
    If I execute the following command with CLI no warnings are shown:

    cppcheck test.c --enable=warning
    

    If I execute the following command in the CLI, I get the warning

    cppcheck test.c --enable=style
    

    Output:

    Checking test.c ...
    test.c:10:8: warning: Variable 'ret' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]
       ret = 2;
           ^
    test.c:8:8: note: $symbol is assigned
       ret = 1;
           ^
    test.c:10:8: note: $symbol is overwritten
       ret = 2;
           ^
    

    Do I do something wrong? I just want to find the same warnings with CLI as are shown in the GUI if I have enabled warnings there.
    If I use the --enable=style option, there are shown too much other messages, which I don't want to display with the "warnings-check".

    Thanks and best regards

    Julian

    Edit: Formatting

     

    Last edit: Julian Wörle 2020-10-14
  • Daniel Marjamäki

    Its a bug in Cppcheck. I can reproduce.

    I have created this ticket: https://trac.cppcheck.net/ticket/9950

     
  • Julian Wörle

    Julian Wörle - 2020-10-15

    Thank you for your answer and for creating the ticket :)

     

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.