誰かが手動で作成したコード例を使用して、静的コードアナライザーの機能を評価しようとするのは好きではありません。 次に、具体的な例を挙げて、合成テストに否定的な態度をとる理由を示します。
少し前まで、Bill Torpeyはブログで「
Even Mo 'Static 」というメモを書き、itc
-benchmarksプロジェクトの分析時にCppcheckおよびPVS-Studioツールがどのように表示されるかについて説明しました。 itc-benchmarksプロジェクトは、トヨタITCの静的分析ベンチマークです。
記事を読んだ後、CppcheckアナライザーとPVS-Studioアナライザーの機能がほぼ同等であるように思われませんでした。 この記事から、一方のアナライザーはもう一方のアナライザーでより優れていることがわかりますが、一般に、それらの診断機能は類似しています。
これは事実ではないと思います。 私の意見では、PVS-StudioアナライザーはCppcheckよりも数倍強力です。 そして一般的に、これは「意見」ではありません、私はそれを知っています!
ただし、PVS-StudioがCppcheckよりも10倍優れていることは外部からは見えないため、その理由を理解する必要があります。 この非常にベンチマークを見て、PVS-Studioがこのテストベースで最高ではないことが判明した理由を見つけることにしました。
理解すればするほど、イライラしました。 そして、ある例が私を完全に不安にさせたので、少し低めに話しましょう。 私の結論は次のとおりです。BillTorpeyについて不満はありません。 彼は良い、正直な記事を書いた。 ビルに感謝します。 しかし、トヨタITCに対して私は主張しています。 私の個人的な意見:彼らのテストベースはがらくたです。 これはもちろん大きな声明ですが、静的コードアナライザーとその評価方法について話すのに十分な資格と経験があると思います。 私の意見では、itc-benchmarksを使用して特定のアナライザーの機能を適切に評価することはできません。
しかし、テスト自体は、最終的に私の心の安らぎから私を引き離しました。
これは、 nullポインター逆参照
テストです。
void null_pointer_001 ()
{
int *p = NULL;
*p = 1; /*Tool should detect this line as error*/
/*ERROR:NULL pointer dereference*/
}
Cppcheck , :
Null pointer dereference: p
PVS-Studio ,
V522.
, PVS-Studio Cppcheck? , !
PVS-Studio , .
,
, . . . , ,
:
void GpuChildThread::OnCrash() {
LOG(INFO) << "GPU: Simulating GPU crash";
// Good bye, cruel world.
volatile int* it_s_the_end_of_the_world_as_we_know_it = NULL;
*it_s_the_end_of_the_world_as_we_know_it = 0xdead;
}
PVS-Studio V522 , . ,
null_pointer_001 . , . , « » .
, V522 A6.
null_pointer_001. A6:
, :- error
- default
- crash
- null
- test
- violation
- throw
- exception
, 0 .. -, «null». -, . . , .
- !
itc-benchmarks . , , :
void null_pointer_006 ()
{
int *p;
p = (int *)(intptr_t)rand();
*p = 1; /*Tool should detect this line as error*/
/*ERROR:NULL pointer dereference*/
}
rand 0, NULL. PVS-Studio ,
rand .
,
rand. , , . , .
. , - , . , PVS-Studio itc-benchmarks, , - .
, ,
rand . , . . .
,
rand 0, 1400 . . - , .
. , , , ,
V501. , itc-benchmarks , , «if (a.x == a.x)». !
, itc-benchmarks . , . , , , . , , :
void overrun_st_014 ()
{
int buf[5];
int index;
index = rand();
buf[index] = 1; /*Tool should detect this line as error*/
/*ERROR: buffer overrun */
sink = buf[idx];
}
, .
, :
return (!strcmp (a->v.val_vms_delta.lbl1,
b->v.val_vms_delta.lbl1)
&& !strcmp (a->v.val_vms_delta.lbl1,
b->v.val_vms_delta.lbl1));
PVS-Studio
GCC. .
,
rand , .
, , , . . . -, .
PVS-Studio.
:- PVS-Studio.
- , PVS-Studio .
- . – , .
, : Andrey Karpov.
Why I Dislike Synthetic Tests