2017-07-24 38 views
0
int* ptrF(); 
void f() 
{ 
    int* p = ptrF(); 
    bool pOK = p && true; 
    if (pOK) 
     *p = 12; // Lint thinks p might be nullptr here 
} 

lint会给出一个警告PC林特,犯错613和“复杂”如果

C:\lint_test\nullptr_with_init.cpp(8): Issue 613: (Warning -- Possible use of null pointer 'p' in argument to operator 'unary *' [Reference: file C:\lint_test\nullptr_with_init.cpp: line 6]) 

有谁知道是否有一个设置使皮棉更“聪明”,并看到POK不能如果p == nullptr,那么返回true?

这是不是改变代码或抑制警告这样

 *p = 12; //lint !e613 

编辑好得多:

Pc Lint, how to suppress err 613(Possible use of null ponter) for class with init() 绝对是一个不同的问题。那是关于如何抑制警告。 这一个是关于如何使皮棉检查“复杂”的if语句(如果可能)

+0

[PC皮棉可能的复制,如何使用init()方法来抑制err 613(可能使用null ponter)类(https://stackoverflow.com/questions/45287883/pc-lint-how-to-suppress-err-613possible-use-of -null-ponter-for-class-in-ini) – user0042

+0

^^只归结为同一点。 – user0042

+0

这两个问题唯一的共同点就是他们是关于错误613。 – Alek86

回答

0

我好像在这种情况下,从指针到bool增加转换将有助于

bool pOK = (bool)p && true;