PC 林特,错误 613 和 "complicated" 如果
PC Lint, err 613 and "complicated" if
int* ptrF();
void f()
{
int* p = ptrF();
bool pOK = p && true;
if (pOK)
*p = 12; // Lint thinks p might be nullptr here
}
棉绒发出警告
C:lint_testnullptr_with_init.cpp(8): Issue 613: (Warning -- Possible use of null pointer 'p' in argument to operator 'unary *' [Reference: file C:lint_testnullptr_with_init.cpp: line 6])
有谁知道是否有一个设置可以使Lint 更"聪明",并看到如果 p == nullptr 则 pOK 不能为真?
这比像这样更改代码或抑制警告要好得多
*p = 12; //lint !e613
编辑:
Pc Lint,如何使用 init(( 抑制类的 err 613(可能使用空 ponter( 是一个完全不同的问题。那是关于如何压制警告的。 这是关于如何使 Lint 检查"复杂"的 if 语句(如果可能的话(
我似乎在这种情况下添加从指针到布尔值的转换会有所帮助
bool pOK = (bool)p && true;
相关文章:
- 如果没有malloc,链表实现将失败
- 如果我只是不访问queue_front节点的子节点,而是将它们推到队列中呢?还是BFS吗
- std::map<struct,struct>::find 找不到匹配项,但是如果我循环通过 begin() 到 end(),我在那里看到匹配项
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 获取日期异步信号安全吗?如果在信号处理程序中使用,它会导致死锁吗
- 设计一个只能由特定类实例化的类(如果可能的话,通过make_unique)
- 线程,如果else语句,都是错误的上下文切换后,会发生什么
- 如果编译的源代码是特定于它编译的硬件的,我们如何分发它
- 如果我std::dynamic_pointer_cast并且底层dynamic_cast的结果为null,那么返回的sh
- C++擦除(如果存在)
- 如果"new int"返回"int*",那么为什么"new int[n]"不返回"int**"?
- 在'如果'陈述输出如何正确
- 如果用户输入无效,如何使用字符串变量-C++重复输入命令
- 如果有一个模板构造函数只有一个泛型参数,为什么我必须有一个复制构造函数
- 如果基类包含双指针成员,则派生类的构造函数
- 如果没有数学库,我如何在C++中创建复利公式
- 如果我已经有一个头,那么模板(-t)文件属于哪里
- 如果C++对象的类在另一个boost模块中声明,如何使用boost将指向该对象的指针返回到python
- 如果条件为TRUE(最佳方式?),则在do while循环中后置增量
- PC 林特,错误 613 和 "complicated" 如果