Menu

Why constArgument (false positive?)

rawl
2019-10-02
2019-10-03
  • rawl

    rawl - 2019-10-02

    I couldn't understand this so I'm reporting it.

    // void *Allocate(void);
    // void Free(void *p);
    
    void f(void)
    {
      void *p;
    
      p = Allocate();
      if(p != NULL)
      {
        Free((void *)p);
      }
    }
    

    cppcheck reports: style: Argument '(void*)p' to function Free is always 1 [constArgument]
    If the (admittedly unnecessary) void pointer cast is removed from the Free() call, it disappears.

    Used cppcheck version is 1.89.
    Older version 1.77 did not report this.

     
  • Paul Fultz

    Paul Fultz - 2019-10-03

    I think this is fixed on the latest master on cppcheck. I think this is related to:

    https://trac.cppcheck.net/ticket/9332

    In the latest, cppcheck we no longer set non-null pointers to 1(which is what caused this error).

     

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.