【2013-12-12】C语言代码检测:cppcheck的使用

📅 2026/7/14 23:58:41
【2013-12-12】C语言代码检测:cppcheck的使用
[历史归档]本文原发布于 cstriker1407.info 个人博客内容为历史存档仅供参考。发布时间2013-12-12 标题C语言代码检测cppcheck的使用分类编程 / C C 标签CC·代码检测·cppcheckC语言代码检测cppcheck的使用官网地址cppcheck的使用界面语言的设置保存输出文件直接检查文件或目录cppcheck的输出文件结果实例输出XML1输出XML2输出TXT输出表格更多参考cppcheck是一个轻量的跨平台的C C 代码静态检查工具使用也很简单这里备份下它的使用方法官网地址【 http://cppcheck.sourceforge.net/ 】下载链接如下图可以下载windows安装包cppcheck源码以及eclipse插件cppcheck的下载和安装在windows上是非常简单的直接【 next 】即可。cppcheck的使用界面语言的设置可在【 编辑 - 首选项 - 语言 】里选择保存输出文件可在【 文件 - 保存结果到文件 】里选择直接检查文件或目录可在【 检查 - 文件/目录 】里选择检查结束后如下图cppcheck的输出文件结果实例cppcheck有4种输出结果输出XML1?xml version1.0 encodingutf-8?resultserrormsgThe scope of the variable len 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: void f(int x) { int i 0; if (x) { // its safe to move int i 0; here for (int n 0; nlt;10; n) { // it is possible but not safe to move int i 0; here do_something(amp;i); } } } When you see this message it is always safe to reduce the variable scope 1 level.severitystyleidvariableScopeline255fileutilssrc\argparse.c/errormsgThe scope of the variable c 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: void f(int x) { int i 0; if (x) { // its safe to move int i 0; here for (int n 0; nlt;10; n) { // it is possible but not safe to move int i 0; here do_something(amp;i); } } } When you see this message it is always safe to reduce the variable scope 1 level.severitystyleidvariableScopeline287fileutilssrc\linked_list_base.c/errormsgVariable r is reassigned a value before the old one has been used.severityperformanceidredundantAssignmentline280fileutilssrc\queue_base.c/errormsgVariable r is reassigned a value before the old one has been used.severityperformanceidredundantAssignmentline294fileutilssrc\queue_base.c/errormsgVariable error is reassigned a value before the old one has been used.severityperformanceidredundantAssignmentline48fileutilssrc\queue_internal.c/errormsgVariable error is reassigned a value before the old one has been used.severityperformanceidredundantAssignmentline49fileutilssrc\queue_internal.c/errormsgVariable error is reassigned a value before the old one has been used.severityperformanceidredundantAssignmentline52fileutilssrc\queue_internal.c/errormsgVariable error is reassigned a value before the old one has been used.severityperformanceidredundantAssignmentline55fileutilssrc\queue_internal.c/errormsgVariable error is reassigned a value before the old one has been used.severityperformanceidredundantAssignmentline57fileutilssrc\queue_internal.c/errormsgVariable error is reassigned a value before the old one has been used.severityperformanceidredundantAssignmentline60fileutilssrc\queue_internal.c/errormsgMemory leak: new_elseverityerroridmemleakline162fileutilssrc\queue_internal.c//results输出XML2?xml version1.0 encodingutf-8?resultsversion2cppcheckversion1.62/-errors-errorverboseThe scope of the variable len 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: void f(int x) { int i 0; if (x) { // its safe to move int i 0; here for (int n 0; nlt;10; n) { // it is possible but not safe to move int i 0; here do_something(amp;i); } } } When you see this message it is always safe to reduce the variable scope 1 level.msgThe scope of the variable len can be reduced.severitystyleidvariableScopelocationline255fileutilssrc\argparse.c//error-errorverboseThe scope of the variable c 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: void f(int x) { int i 0; if (x) { // its safe to move int i 0; here for (int n 0; nlt;10; n) { // it is possible but not safe to move int i 0; here do_something(amp;i); } } } When you see this message it is always safe to reduce the variable scope 1 level.msgThe scope of the variable c can be reduced.severitystyleidvariableScopelocationline287fileutilssrc\linked_list_base.c//error-errorverboseVariable r is reassigned a value before the old one has been used.msgVariable r is reassigned a value before the old one has been used.severityperformanceidredundantAssignmentlocationline279fileutilssrc\queue_base.c/locationline280fileutilssrc\queue_base.c//error-errorverboseVariable r is reassigned a value before the old one has been used.msgVariable r is reassigned a value before the old one has been used.severityperformanceidredundantAssignmentlocationline293fileutilssrc\queue_base.c/locationline294fileutilssrc\queue_base.c//error-errorverboseVariable error is reassigned a value before the old one has been used.msgVariable error is reassigned a value before the old one has been used.severityperformanceidredundantAssignmentlocationline46fileutilssrc\queue_internal.c/locationline48fileutilssrc\queue_internal.c//error-errorverboseVariable error is reassigned a value before the old one has been used.msgVariable error is reassigned a value before the old one has been used.severityperformanceidredundantAssignmentlocationline48fileutilssrc\queue_internal.c/locationline49fileutilssrc\queue_internal.c//error-errorverboseVariable error is reassigned a value before the old one has been used.msgVariable error is reassigned a value before the old one has been used.severityperformanceidredundantAssignmentlocationline49fileutilssrc\queue_internal.c/locationline52fileutilssrc\queue_internal.c//error-errorverboseVariable error is reassigned a value before the old one has been used.msgVariable error is reassigned a value before the old one has been used.severityperformanceidredundantAssignmentlocationline52fileutilssrc\queue_internal.c/locationline55fileutilssrc\queue_internal.c//error-errorverboseVariable error is reassigned a value before the old one has been used.msgVariable error is reassigned a value before the old one has been used.severityperformanceidredundantAssignmentlocationline55fileutilssrc\queue_internal.c/locationline57fileutilssrc\queue_internal.c//error-errorverboseVariable error is reassigned a value before the old one has been used.msgVariable error is reassigned a value before the old one has been used.severityperformanceidredundantAssignmentlocationline57fileutilssrc\queue_internal.c/locationline60fileutilssrc\queue_internal.c//error-errorverboseMemory leak: new_elmsgMemory leak: new_elseverityerroridmemleaklocationline162fileutilssrc\queue_internal.c//error/errors/results输出TXT: (style) The scope of the variable len can be reduced. : (style) The scope of the variable c can be reduced. - : (performance) Variable r is reassigned a value before the old one has been used. - : (performance) Variable r is reassigned a value before the old one has been used. - : (performance) Variable error is reassigned a value before the old one has been used. - : (performance) Variable error is reassigned a value before the old one has been used. - : (performance) Variable error is reassigned a value before the old one has been used. - : (performance) Variable error is reassigned a value before the old one has been used. - : (performance) Variable error is reassigned a value before the old one has been used. - : (performance) Variable error is reassigned a value before the old one has been used. : (error) Memory leak: new_el输出表格更多参考【 http://blog.csdn.net/e5max/article/details/11489137 】【 http://blog.csdn.net/akof1314/article/details/7477014 】【 http://www.cnblogs.com/lancidie/archive/2013/04/13/3019505.html 】【 http://www.ibm.com/developerworks/cn/java/j-codan/ 】【 http://www.wuqifu.com/2013/05/07/c静态代码检查工具cppcheck/ 】