是的。 Lint就是为此而设计的。我们在嵌入式系统和汽车系统中使用它很多。 You can use the online demo to test out how well it would work for you.在特定情况下,它的规则MISRA:2012:18.6.
样品试验
FlexeLint for C/C++ (Unix) Vers. 9.00L, Copyright Gimpel Software 1985-2014
--- Module: misra3.c (C)
_
1 int main() {
misra3.c 1 Note 970: Use of modifier or type 'int' outside of a typedef [MISRA 2012 Directive 4.6, advisory]
misra3.c 1 Note 9075: external symbol 'main(void)' defined without a prior declaration [MISRA 2012 Rule 8.4, required]
_
2 int *a;
misra3.c 2 Note 970: Use of modifier or type 'int' outside of a typedef [MISRA 2012 Directive 4.6, advisory]
3 {
_
4 int b = 42;
misra3.c 4 Note 970: Use of modifier or type 'int' outside of a typedef [MISRA 2012 Directive 4.6, advisory]
_
5 a = &b;
misra3.c 5 Info 733: Assigning address of auto variable 'b' to outer scope symbol 'a' [MISRA 2012 Rule 18.6, required]
6 }
_
7 printf("%d", *a); // UB!
misra3.c 7 Info 718: Symbol 'printf' undeclared, assumed to return int [MISRA 2012 Rule 17.3, mandatory]
misra3.c 7 Warning 586: function 'printf' is deprecated. [MISRA 2012 Rule 21.6, required]
misra3.c 7 Info 746: call to function 'printf()' not made in the presence of a prototype
8 return 0;
_
9 }
misra3.c 9 Info 783: Line does not end with new-line
misra3.c 9 Note 954: Pointer variable 'a' (line 2) could be declared as pointing to const [MISRA 2012 Rule 8.13, advisory]
/// Start of Pass 2 ///
--- Module: misra3.c (C)
1 int main() {
2 int *a;
3 {
4 int b = 42;
5 a = &b;
6 }
7 printf("%d", *a); // UB!
8 return 0;
9 }
--- Global Wrap-up
Warning 526: Symbol 'printf()' (line 7, file misra3.c) not defined
Warning 628: no argument information provided for function 'printf()' (line 7, file misra3.c)
我敢打赌,Purify的确如此,但我不知道现在Valgrind和其他免费工具如何激增。 –
C和C++不是同一种语言。这些日子他们非常不同。 – tambre
@FrançoisAndrieux*问题工具在Stack Overflow中显式地脱离主题*但是可能会通过“** How **可以检测超出范围变量的访问权限”的简单更改。我不认为提问者是一个noob ... –