cpp-tscancode
Skill8 starsChanged 16 days agoApache-2.0View on GitHub
使用 TscanCode(腾讯开源)对 C/C++ 代码做静态分析,检测缺陷、安全漏洞与风格问题。适用于 C/C++ 项目快速缺陷扫描、安全审计、CI 集成。
In this repository32 other files it gives its agents.
- AGENTS.mdAGENTS.md
- ast-grep-blockSkill
- code-deconstructSkill
- code-detect-dupSkill
- code-detect-problemSkill
- code-part-modificationSkill
- code-refactorSkill
- code-reviewSkill
- cpp-checkSkill
- cpp-clang-tidySkill
- full-analysisSkill
- gdb-heap-analysisSkill
- java-asprofSkill
- java-check-pmdSkill
- java-check-spotbugsSkill
- java-coverageSkill
- java-envSkill
- java-g2mSkill
- jmh-benchSkill
- lets-loopSkill
- long-term-taskSkill
- md2pdfSkill
- merge-agents-mdSkill
- qualitative-assessmentSkill
- requirement-collectSkill
- rust-clippySkill
- rust-flamegraphSkill
- shell-checkSkill
- sql-extractSkill
- sync-dev-specSkill
- sync-repo-docsSkill
- vbox-test-envSkill
The file
Files
TscanCode C/C++静态分析技能
本文件中的
templates/...均指本技能目录下的templates/子目录。
工具位置
TSCANCODE=${HOME}/app/TscanCode.linux/tscancode执行流程
- 确定源代码路径:
SRC_DIR=src(根据项目结构调整) - 执行分析(按需选择级别):
# 基础检查
$TSCANCODE $SRC_DIR
# 完整检查(含风格、性能、可移植性)
$TSCANCODE --enable=all $SRC_DIR 2> tscancode-full.txt
# 仅警告检查
$TSCANCODE --enable=warning $SRC_DIR 2> tscancode-warning.txt
# 风格和性能检查
$TSCANCODE --enable=style,performance $SRC_DIR 2> tscancode-style.txt- 指定输出格式:
# 文本格式(默认,输出到stderr)
$TSCANCODE --enable=all $SRC_DIR 2> tscancode.txt
# XML格式
$TSCANCODE --enable=all --xml $SRC_DIR 2> tscancode.xml
# 静默模式
$TSCANCODE --quiet --enable=all $SRC_DIR 2> tscancode.txt- 处理结果:
# 统计问题类型
grep -oP '\[.*?\]' tscancode.txt | sort | uniq -c | sort -nr
# 提取高危问题
grep -E '(error|warning):' tscancode.txt常用参数
| 参数 | 描述 | 示例 |
--enable=<id> | 启用检查类别 | warning, style, performance, portability, information, all |
-I <dir> | 包含目录 | -I include -I /usr/include |
-D<macro> | 定义宏 | -DDEBUG -DNDEBUG |
-U<macro> | 取消宏定义 | -UDEBUG |
-j <n> | 并行检查线程数 | -j 4 |
--quiet | 静默模式 | --quiet |
--xml | XML格式输出 | --xml |
检查类别
| 类别 | 关键检查项 |
| warning | 空指针解引用、数组越界、整数溢出、未初始化变量、内存泄漏、双重释放 |
| style | 冗余代码、复杂表达式、变量作用域、命名规范 |
| performance | 按值传递、冗余拷贝、低效算法 |
| portability | 平台依赖、类型大小假设 |
| information | 缺少包含、配置问题 |
| unusedFunction | 定义但未被调用的函数 |
典型场景
| 场景 | 命令 |
| 快速检查 | $TSCANCODE --enable=warning $SRC_DIR 2> tscancode-warning.txt |
| 完整检查 | $TSCANCODE --enable=all -j 4 $SRC_DIR 2> tscancode-full.txt |
| 特定目录 | $TSCANCODE --enable=all -I include src/core/ 2> tscancode-core.txt |
| CI集成 | $TSCANCODE --quiet --enable=warning --xml $SRC_DIR 2> tscancode-report.xml |
| 宏控制 | $TSCANCODE --enable=all -DDEBUG $SRC_DIR 2> tscancode-debug.txt |
构建系统集成
模板文件位于 templates/ 目录:
tscancode-check.sh- Shell脚本封装tscancode-summary.sh- 摘要报告生成CMakeLists-tscancode.txt- CMake集成目标Makefile-tscancode- Makefile集成
最佳实践
- 增量检查:大型项目使用
-j并行加速 - 分级处理:先修复 error,再处理 warning,最后优化 style
- 包含路径:确保
-I参数包含所有必要的头文件路径 - 宏定义:正确设置
-D参数以覆盖所有代码路径 - CI集成:将 TscanCode 纳入持续集成流程
注意事项
- TscanCode 默认输出到 stderr,需重定向
2>捕获 --enable=all会启用 unusedFunction,建议全项目扫描- 确保
-I路径正确,否则可能误报缺少包含
技能版本: 1.0.0 | 适用项目: C/C++ | 输出位置: 当前目录 tscancode-*.txt
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

