2017-07-24 35 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;