PC Lint,如何使用init()抑制类的err 613(可能使用null ponter) [英] Pc Lint, how to suppress err 613(Possible use of null ponter) for class with init()

查看:221
本文介绍了PC Lint,如何使用init()抑制类的err 613(可能使用null ponter)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图尽可能简化情况.所以我有一堂课:

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; }
};

生成2个Lint警告613(可能使用空指针'C :: i'...)

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

我知道调用getI1()或getI2()时字段"不会为空.不幸的是,我无法在构造函数中对其进行初始化.因此,我想禁止棉绒警告.我可以这样做

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
};

但在我的真实情况下:

1)这样的类很多,每个类都有很多 使用此指针的函数.

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

2)我的管理人员不允许我添加太多皮棉 代码中的注释.

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

所以我的问题是:有谁知道一个命令行选项,该选项可以让我告诉Lint:我知道代码不是最好的,只是停止检查此特定成员变量是否为null"?

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"?

也许类似于-sem参数?

Something similar to -sem parameter, maybe?

推荐答案

我知道代码是错误的,应该将其修复,依此类推.不幸的是,我现在无法做到这一点(由于一个人的巨大努力和高风险的变更),但是这些错误使其他有时甚至是更为严重的问题不堪重负

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)

这篇关于PC Lint,如何使用init()抑制类的err 613(可能使用null ponter)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆