2017-04-05 13 views
0
#include<stdio.h> 
#include <stdlib.h> 

int test() { 
    const char* s = getenv("CNU"); 
    if (s!=NULL) 
    return 1; 
    else 
    return -1; 
} 

int main() { 
    test(); 
    // some C code.. 
    return 0; 
} 

命令我使用的Coverity的分析:爲什麼不在我的程序中顯示CHECKED_RETURN?

cov-build --dir Cov.build gcc test.c 
cov-analyze --dir Cov.build --aggressiveness-level high --enable-callgraph-metrics --all 

報告:

Analysis summary report: 
------------------------ 
Files analyzed     : 1 
Total LoC input to cov-analyze : 10926 
Functions analyzed    : 2 
Paths analyzed     : 6 
Time taken by analysis   : 00:00:01 
Defect occurrences found  : 0 

關於CHECKED_RETURN: https://ondemand.coverity.com/reference/7.6.1/en/coverity

回答

1

CHECKED_RETURN檢查是一個統計通道ecker - 它查找檢查返回值的示例,並且如果達到統計顯着(可配置)的閾值,那麼將針對未檢查返回值的位置發出缺陷。

如果你想,只要你不檢查返回值,它總是發出缺陷,那麼你需要添加__coverity_always_check_return__(),如在文檔中,你鏈接的例子:

int always_check_me(void) { 
    __coverity_always_check_return__(); 
    return rand() % 2; 
} 

int main(int c, char **argv) { 
    always_check_me(); #defect#checked_return 
    // the statement above is a defect because the value is not checked 
    cout << "Hello world" << endl; 
} 

由於顯而易見的原因,你還需要爲源編譯創建一個函數存根(也在文檔中提到)。如果您想讓代碼僅用於Coverity,則可以使用#if __COVERITY__加以保護。

0

是的,CHECKED_RETURN是統計檢查器錯誤。如果你在10個地方檢查test()的返回值,那麼在第11個地方如果你錯過檢查test()的返回值,覆蓋將返回CHECKED_RETURN錯誤。答案顯示有多少地方檢查出總使用量的統計數據。

相關問題