0

特定のコード行で変数の可能な値の範囲を決定する必要があります。複雑なプロジェクトでは、これは非常に面倒でエラーが発生しやすくなります。そのため、このタスクを自動化する可能性を模索しています。次の簡単なコード スニペットを想像してみてください。

#define checkBoundary(value) if((value)<100 || (value)> 1000) return;

bool checkmaximumForMode0(value)
{
    return (value>100);
}

void main(void)
{
    int mode = rand()%4;
    // x shall be any valid value for an int, just for the sake of completion i use rand here.
    int x = rand();
    if (x < 0) 
        return;
    switch(mode)
    {
    case 0:
        if(checkmaximumForMode0(x)) return;
    case 1: 
        checkBoundary(x);
    default:
        if (x<10000)
            goto exit;
    }
    // Now i want to know, which value range of x will i have under what circumstances
    int isChecked = x;
    // For this easy example:
    // Codepath 1(mode = 0): x >= 0 && x <= 100
    // Codepath 2(mode = 1): x >= 100 && x <= 1000
    // Codepath 3(mode = 2..3): x >= 10000 && x <= maxint
exit:
    print( "Exiting");
    return
}

このタスクを完全に達成するためのツールまたはその他の方法を知っている人はいますか? さらに、結果の値の範囲を特定の値の範囲のセットに対してチェックし、理想的には結果として非互換性のみを取得したいと考えています。

4

2 に答える 2

1

We're currently using the clang static analyzer (http://clang-analyzer.llvm.org/) and cppcheck (which works for C as well): http://cppcheck.sourceforge.net/

cppcheck is (besides lot of additional checks) able to check out of bounds access on buffers by analyzing the data flow. See also: http://sourceforge.net/p/cppcheck/wiki/ListOfChecks.

Last but not least sonarqube comes with some additional checks (you have to pay for the C/C++ plugin) and is able to present everything on a web page. Connection to Jenkins is possible as well as integration of cppcheck results and/or code coverage: http://www.sonarqube.org

于 2015-12-02T18:11:51.133 に答える
0

Polyspaceは値の範囲を解析できますが、独自のソリューションです。

于 2015-12-04T15:36:06.657 に答える