I suggest you ...

Extend value tracking for member variables/functions

#include <string.h>
//lint -passes(2)
class X
{
int *p;
public:
X(){ p = NULL; }
bool IsValid()const{return p != NULL;}
void Foo()
{
if(IsValid())
*p = 0; // Warning 613: Possible use of null pointer (wrong)
}
void Bar()
{
if(p != NULL)
*p = 0; // no 613 here (ok)
}
};

// Value tracking works for global variables (ok)
int *pg = NULL;
bool IsValid(const int* px)
{
return px != NULL;
}
void Bar()
{
if(IsValid(pg))
*pg = 0;// no 613 here (ok)
}

1 vote
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    Magnus shared this idea  ·   ·  Admin →

    0 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...

      Feedback and Knowledge Base