文章目录
网站
https://cwe.mitre.org/data/definitions/686.html
398
风格问题,如果一个局部变量,可以放在一个更小的区域,而且满足使用,最好是将作用域缩小。但是需要注意不要搞错。检查工具有点时候,检查有问题。
[STYLE] (cwe=398, variableScope):
The scope of the variable ‘left’ can be reduced., The scope of the variable ‘left’ can be reduced. Warning: Be careful when fixing this message, especially when there are inner loops. Here is an example where cppcheck will write that the scope for ‘i’ can be reduced:\012
void f(int x)\012
{
\012 int i = 0;
\012 if (x) {
\012 // it’s safe to move ‘int i = 0;’ here
\012 for (int n = 0; n < 10; ++n) {
\012 // it is possible but not safe to move ‘int i = 0;’ here
\012 do_something(&i);
\012 }
\012 }
\012}
\012When you see this message it is always safe to reduce the variable scope 1 level.
686
可移植性,非法打印参数类型。%x,需要一个无符号数,但是给的确实有符号长整型。
[PORTABILITY] (cwe=686, invalidPrintfArgType_uint): %x in format string (no. 1) requires ‘unsigned int’ but the argument type is ‘uintptr_t {aka unsigned long}’., %x in format string (no. 1) requires ‘unsigned int’ but the argument type is ‘uintptr_t {aka unsigned long}’.