当另一个函数返回指针时,未检测到空指针解除引用问题 [英] Null Pointer Dereference issue not detected when the pointer is returned by another function
问题描述
我使用SonarQube(带有cppecheck 1.70的5.1)分析C代码. 在下面的示例中,SonarQube和/或Cppcheck(由Sonar使用)应该检测到空指针取消引用问题.但是,由Cppcheck拒绝的SonarQube没有发现任何问题.
I use SonarQube (5.1 with cppecheck 1.70) to analyse C-code. In following example, there is a Null Pointer Dereference issue that should be detected by SonarQube and/or Cppcheck (used by Sonar). But no issue found by SonarQube niether repported by Cppcheck.
struct s1
{
char c1;
char c2;
};
struct s1 * toto1(void)
{
return NULL;
}
void toto2(void)
{
struct s1* my_st=NULL;
my_st = toto1();
my_st->c1 = 1;
my_st->c2 = 0;
return;
}
在这种情况下,此规则是否有任何限制(不应取消引用空指针)?
Is there any restriction on this rule (Null pointers should not be dereferenced) in such situation?
推荐答案
我是Cppcheck开发人员.
I am a Cppcheck developer.
我很惊讶Cppcheck没有检测到它.
I was surprised that Cppcheck does not detect that.
我已经在上游创建了该票证: http://trac.cppcheck.net/ticket/7132
I have created this ticket upstream: http://trac.cppcheck.net/ticket/7132
谢谢!如果您发现更多假阴性,请告诉我.
Thank you! Let me know if you discover more false negatives.
这篇关于当另一个函数返回指针时,未检测到空指针解除引用问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!