PC 林特,错误 613 和 "complicated" 如果

PC Lint, err 613 and "complicated" if

本文关键字:complicated 如果 林特 错误 PC      更新时间:2023-10-16
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;
相关文章: