Menu

False positive assertWithSideEffect with function pointer comparison

5 days ago
4 days ago
  • correctmost

    correctmost - 5 days ago

    I am seeing a false positive assertWithSideEffect warning when an assert contains a function pointer comparison.

    Here is sample code based on code from glib-networking:

    #include <assert.h>
    
    typedef struct
    {
      bool field;
    } st;
    
    static bool handshake ()
    {
      st *priv;
      priv->field = true;
      return true;
    }
    
    int main()
    {
      bool (*fptr)() = handshake;
      assert (handshake == fptr);  # warning: Assert statement calls a function which may have desired side effects: 'handshake'. [assertWithSideEffect]
      return 0;
    }
    

    I don't think a function call is actually being made in this case.

    Versions tested:
    dfcec18902 and 2.21.1 (Arch Linux)

     
  • CHR

    CHR - 4 days ago

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

     

Log in to post a comment.