Search code examples
c++nullptrpc-lint

Pc Lint, how to suppress err 613(Possible use of null ponter) for class with init()


Tried to simplify the situation as much as possible. So I have a class:

class C
{
    int * field;
public:
    C() : field(nullptr) {}
    void init(int* f) { field = f; }

    int getI1() { return *field; }
    int getI2() { return *field; }
};

which generates 2 Lint warnings 613 (Possible use of null pointer 'C::i'...)

I know that "field" won't be null when getI1() or getI2() are called. And unfortunately I cannot initialize it in constructor. So I want to suppress Lint warnings. I can do it like this

class C
{
    int * field;
public:
    C() : field(nullptr) {}
    void init(int* f) { field = f; }

    int getI1() { return *field; } //lint !e613
    int getI2() { return *field; } //lint !e613
};

but in my real case:

1) There are rather many such classes and each class has many functions that use this pointer.

2) My managements doesn't allow me to add too many lint comments in the code.

So my question: does anyone know a command-line option that will let me tell Lint "I know the code is not best, just stop checking this particular member variable for null"?

Something similar to -sem parameter, maybe?


Solution

  • I know that code is bad, should be fixed and so on. Unfortunately I cannot do it right now (because of huge amount of effort for one person and highly risky changes), but those errors were overwhelming other, sometimes more critical, problems

    I found out that to suppress this warning in one line you can do:

    -esym(613, C::field)