其他分享
首页 > 其他分享> > CWE:通病总结

CWE:通病总结

作者:互联网

文章目录

网站

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}’.

标签:总结,cwe,int,通病,unsigned,012,scope,CWE,reduced
来源: https://blog.csdn.net/qq_36428903/article/details/121965667