Menu

False positive: The address of local variable x is accessed at non-zero index.

2019-12-23
2019-12-29
  • Sergey Burgsdorf

    Hello! We are using cppcheck for our codebase and we get this strange error since the check was introduced in 1.88.
    I managed to reduce it to a somewhat small code example.
    Is this a false positive, or I am not seeing something?

    Changing std::map to an array removes the error from check.
    Changing the map to <int, int> does not produce an error as well.

    Get this error twice here, on assigning indices 1 and 2. In our real code, there are dozens of those errors that look unjustified.

    Edit: adding the errors.
    [TestApp.cpp:33] (error) The address of local variable 'm_ObjectDummy' is accessed at non-zero index. [objectIndex]
    [TestApp.cpp:34] (error) The address of local variable 'm_ObjectDummy' is accessed at non-zero index. [objectIndex]

    Thank you.

    class CObject
    {
    public:
      CObject()
      {
      }
      virtual ~CObject()
      {
      }
    };
    
    class CTestClass
    {
    public:
      CTestClass();
      virtual ~CTestClass();
    
    protected:
      CObject m_ObjectDummy;
      std::map<int, CObject*> m_ObjectMap;
    };
    
    CTestClass::CTestClass()
      : m_ObjectDummy()
    {
      m_ObjectMap[0] = &m_ObjectDummy;
      m_ObjectMap[1] = &m_ObjectDummy;
      m_ObjectMap[2] = &m_ObjectDummy;
    }
    
    CTestClass::~CTestClass()
    {
    }
    
    void main()
    {
    }
    
     

    Last edit: Sergey Burgsdorf 2019-12-24
  • Paul Fultz

    Paul Fultz - 2019-12-29

    This is a false positive. I created a ticket here:

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

     
  • Sergey Burgsdorf

    Thank you Paul, also thanks for further reducing it.
    I will ask for a trac account, since I have a few more.

     
  • Daniel Marjamäki

    Sergey; if you want a trac account I can create it for you.. please generate a htpasswd hash and send it to me. You can generate it locally on your computer or online (google "htpasswd generator").

     

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.