【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/ 】

相关新闻

YOLOv8轴承缺陷检测:工业质检的深度学习实战指南

YOLOv8轴承缺陷检测:工业质检的深度学习实战指南

在工业质检领域,轴承缺陷检测一直是个让人头疼的问题。传统的人工目视检测不仅效率低下,还容易因疲劳导致误判,而基于传统机器视觉的方法在面对复杂背景和微小缺陷时往往力不从心。但今天要介绍的YOLOv8轴承缺陷识别检测系统,用实…

2026/7/17 8:08:35
Windows C盘清理全攻略:从手动操作到自动化工具释放磁盘空间

Windows C盘清理全攻略:从手动操作到自动化工具释放磁盘空间

在 Windows 系统长期使用过程中,C 盘空间不足是困扰许多用户的常见问题。系统更新残留、临时文件堆积、应用缓存膨胀等因素会迅速吞噬宝贵的磁盘空间,导致系统运行缓慢、软件安装失败甚至系统崩溃。手动清理不仅效率低下,还可能误删关键文件。…

2026/7/17 8:18:02
Gradle 下载与依赖加速全攻略(含多镜像源+原理深度解析)

Gradle 下载与依赖加速全攻略(含多镜像源+原理深度解析)

🚀 告别龟速构建!Gradle 下载与依赖加速全攻略(含多镜像源+原理深度解析) 在 Android 和 Java 开发中,Gradle 作为核心构建工具,其下载和依赖解析速度直接影响开发效率。如果你经常遇到构建卡顿、下载超时,或是 Sync 项目时进度条一动不动,那么很可能是默认的国外源拖…

2026/7/22 4:29:36

最新新闻

JetBrains Air IDE:面向AI原生开发的容器化IDE架构

JetBrains Air IDE:面向AI原生开发的容器化IDE架构

1. JetBrains Air IDE 是什么?不是“又一个AI IDE”,而是IDE架构的范式迁移JetBrains Air IDE 这个名字刚出来时,我第一反应是:又一个套着AI外壳的玩具产品?毕竟过去两年,“AI IDE”这个词已经被各种创业公…

2026/7/22 5:44:04
从PEP 517到wheel构建:深入解析bottleneck安装失败的根本原因与系统化修复

从PEP 517到wheel构建:深入解析bottleneck安装失败的根本原因与系统化修复

1. 当Python遇上C扩展:bottleneck安装失败背后的技术困局 那天下午,我正在为一个时间序列分析项目配置环境。当执行 pip install bottleneck 时,熟悉的红色错误提示突然跳出:"ERROR: Could not build wheels for bottlenec…

2026/7/22 5:42:03
Swindler事件系统详解:如何监听并响应窗口状态变化

Swindler事件系统详解:如何监听并响应窗口状态变化

Swindler事件系统详解:如何监听并响应窗口状态变化 【免费下载链接】Swindler macOS window management library for Swift 项目地址: https://gitcode.com/gh_mirrors/sw/Swindler Swindler是一款强大的macOS窗口管理Swift库,提供了全面的事件系…

2026/7/22 5:42:20
CANN/asc-devkit绝对值计算API

CANN/asc-devkit绝对值计算API

asc_abs 【免费下载链接】asc-devkit 本项目是CANN 推出的昇腾AI处理器专用的算子程序开发语言,原生支持C和C标准规范,主要由类库和语言扩展层构成,提供多层级API,满足多维场景算子开发诉求。 项目地址: https://gitcode.com/ca…

2026/7/22 5:41:48
CANN/ops-sparse稀疏算子开发指南

CANN/ops-sparse稀疏算子开发指南

{算子名称}算子 【免费下载链接】ops-sparse 本项目是CANN提供的高性能稀疏矩阵计算的算子库,专注于优化稀疏矩阵的计算效率。 项目地址: https://gitcode.com/cann/ops-sparse 算子概述 {一段话描述算子的功能定位和核心运算。例如:"{op} 算…

2026/7/22 5:42:31
MATLAB工具箱实战:从零安装CVX到解决首个凸优化问题

MATLAB工具箱实战:从零安装CVX到解决首个凸优化问题

1. CVX工具箱简介与安装准备CVX是一个专门用于解决凸优化问题的MATLAB工具箱,它能让用户用接近数学表达式的语法来描述和求解优化问题。我第一次接触CVX是在研究生阶段做信号处理项目时,当时需要解决一个复杂的投资组合优化问题,传统方法代码…

2026/7/22 5:43:41

日新闻

周新闻

月新闻