Menu

False positive: Pointer expression converted to bool is always true

2023-11-09
2023-11-09
  • Pauli Järvinen

    Pauli Järvinen - 2023-11-09

    The following code with a function pointer returning a bool reports a false positive on cppcheck 2.12.1:

    static bool (*ptr)(void);
    
    void f()
    {
        if (ptr == NULL || !ptr()) {
            printf("Not true\n");
        }
    }
    
    test/test.c:5:25: style: Pointer expression 'ptr' converted to bool is always true. [knownPointerToBool]
        if (ptr == NULL || !ptr()) {
                            ^
    
     
  • CHR

    CHR - 2023-11-09

    Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/12170

     

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.