Menu

nullPointerRedundantCheck with new(std::nothrow)

2019-10-14
2019-10-14
  • Igor Loboda

    Igor Loboda - 2019-10-14

    Hi,

    Is this a false positive or I'm doing something wrong?

    #include <new>
    
    int main(int, char**)
    {
      auto* pNumber = new (std::nothrow) int;
    
      if (nullptr == pNumber)
      {
        return 1;
      }
    
      delete pNumber;
      pNumber = nullptr;
    
      return 0;
    }
    

    Cppcheck produces

    cppcheck_nothrow.cpp:5: warning (nullPointerRedundantCheck): Either the condition 'nullptr==pNumber' is redundant or there is possible null pointer dereference: new(std::nothrow)int.
    

    Cppcheck 1.90 dev

    Thank you,
    Igor

     
  • versat

    versat - 2019-10-14

    I do not see anything wrong here.
    Looks like a false positive. I will create a ticket for this issue.

     
  • versat

    versat - 2019-10-14

    Thanks for the report, i have now created a ticket: https://trac.cppcheck.net/ticket/9414

     
  • Igor Loboda

    Igor Loboda - 2019-10-14

    Great, thanks

     

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.