Open
docs: print ACL error messages safely in RAS guides #133
docs: print ACL error messages safely in RAS guides #133
Open
tianjunAdd on Oct 2
tianjun
Oct 2

描述

中英文 docs/*/debug/op_debug_prof.md 均直接 printf(aclGetRecentErrMsg())。该 API 返回错误消息文本,作为格式字符串会导致 -Werror=format-security 编译失败,并将消息中的百分号格式指令当成参数访问;空指针返回也没有保护。

中英文合并为一个修复:保存返回指针,非空时使用固定 "%s" 格式打印,并将该代码块语言标记为 cpp。

关联的Issue

Fixes #61

测试

Host clang++ 包含 cann/runtime 真实公开 acl/acl.h,使用错误消息返回值替身复现真实文档语句。原例开启 -Wformat -Werror=format-security 后编译失败;修复后编译通过,含 %s 与 100% 的文本逐字打印,空指针跳过。没有设备运行或真实 ACL 初始化。git diff --check 通过。 仓库适用 pre-commit hooks 与 diff --check 通过。

本地无 NPU,未执行设备测试;提交后评论 /compile。

文档更新

  • docs/zh/debug/op_debug_prof.md
  • docs/en/debug/op_debug_prof.md

类型标签

likedislike
Merge blocked
Ttianjun
Oct 2 Created pull request, commit d1fdacb3
Ttianjun
Oct 2 Associated issue: [Documentation|文档反馈] op_debug_prof 中英文示例将错误日志用作 printf 格式字符串
atomgit-bot
atomgit-bot
Oct 2 Comments:

变更摘要

本 PR 针对中英文 debug 调试文档中打印 ACL 错误消息的示例代码进行安全性修正。原示例直接以 printf(aclGetRecentErrMsg()) 调用,将 API 返回的错误消息文本当作格式字符串使用,既会在 -Werror=format-security 下编译失败,也会把消息中出现的百分号格式指令误当成参数解析,且未对空指针返回做保护。修复方式是将返回值先保存到指针变量,在非空时以固定的 "%s" 格式打印,并把对应代码块语言标记改为 cpp,中英文文档同步处理。

主要改动

  • 避免返回值直接作为格式字符串: 不再直接 printf(aclGetRecentErrMsg()),而是先保存返回指针再以固定 "%s" 格式输出,消除 -Werror=format-security 编译失败与百分号被解析为格式指令的问题。
  • 增加空指针保护: 仅在返回指针非空时执行打印,跳过空指针场景。
  • 统一代码块语言标记: 将相关示例代码块的语言标记改为 cpp。
  • 中英文文档同步修复: 同一修复同时应用于 docs/zh/debug/op_debug_prof.md 与 docs/en/debug/op_debug_prof.md。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
Oct 2 Comments:

🤖 本次改动均为数据 / 生成 / 二进制文件(如测试用例、锁文件、媒体资源),没有可审查的代码逻辑,已跳过 AI 代码审查。

likedislike
Incorrect?
CANN-robot
CANN-robotCollaborators
Oct 2 Comments:

Hi @Ethan_Zou, welcome to submitting your first PR to ops-ras!

PR Merge Steps

1. CLA Signing

If the current PR label includes cann-cla/yes, it means you have signed the CLA and can proceed to the next step. If the label includes cann-cla/no, please sign the CLA first. If you have any questions, please refer to the FAQ.

2. CI Check

Please comment /compile to trigger the CI pipeline check. If the CI run is successful, the PR will be tagged with ci-pipeline-passed and you can proceed to the next step. If the CI run fails, the PR will be tagged with ci-pipeline-failed, please check the CI logs to fix the issues in the PR. If you have any questions, please refer to the FAQ.

3. Code Review

After CI passes, please refer to the PR Approval Progress and proactively @ the committers in the table to review the code. After approval, committers will comment /lgtm and /approve. Once the lgtm and approved labels are successfully added, the PR will be merged automatically.

likedislike
CANN-robotCANN-robotCollaborators
Oct 2 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Oct 2 Comments:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here.
You can get sig-info at here.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.


PR Approval Progress

⚠️ This PR does not yet meet the following requirements:lgtm (requires ≥ 2 person(s) per module)、approve (requires ≥ 1 person(s) per module)

Module Approval Details

module lgtm status approve status
repo-cann/ops-ras ❌ (0/2)(You can also ask: 徐鲁威, 王林木, 唐燕峰, 周奇龙, 陈兴宇) ❌ (0/1)(You can also ask: 徐鲁威, 柳宗谷, 唐燕峰, 於欣洁, 王林木)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

Ethan_Zou, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
tianjun
Oct 2 Comments:

/compile

likedislike
CANN-robotCANN-robotCollaborators
Oct 2 Added label: ci-pipeline-running
CANN-robot
CANN-robotCollaborators
Oct 2 Comments:

流水线任务触发成功
任务链接 [539c3bcc16a94d3e993fa51f202d1639][流水线指导]

任务名称状态日志下载链接
PreSmoke_ATK_Test_A2 ✅ SUCCESS >>>>>

[2026-10-02 13:32:50]    CI执行结束

likedislike
CANN-robot
CANN-robotCollaborators
Oct 2 Comments:

流水线任务触发成功
任务链接 [634dc03fdc184692a8137f34a105034f][流水线指导]

任务名称状态日志下载链接
Compile_Ascend_X86 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_single ✅ SUCCESS >>>>> >>>>>
pre_comment ✅ SUCCESS >>>>>
Compile_Ascend_X86_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_single_ubuntu24 ✅ SUCCESS >>>>> >>>>>
UT_Test_ophost ✅ SUCCESS
UT_Test_opapi ✅ SUCCESS
API_Check ✅ SUCCESS >>>>>

[2026-10-02 13:35:02]    CI执行结束

likedislike
CANN-robot
CANN-robotCollaborators
Oct 2 Comments:

流水线任务触发成功
任务链接 [fa301971454647ac87340f541eacd3a9][流水线指导]

任务名称状态日志下载链接
codecheck ✅ SUCCESS >>>>>
SCA ✅ SUCCESS >>>>>
antipoison ✅ SUCCESS >>>>>
codecheck_Pr ✅ SUCCESS
codecheck_codestyle ✅ SUCCESS >>>>>
codecheck_precommit ✅ SUCCESS >>>>>

[2026-10-02 13:34:30]    CI执行结束

likedislike
CANN-robotCANN-robotCollaborators
Oct 2 Added label: api-check-pass
CANN-robotCANN-robotCollaborators
Oct 2 Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Oct 2 Added label: ci-pipeline-passed
tianjun
29 days ago Comments:

/compile

likedislike
CANN-robotCANN-robotCollaborators
29 days ago Removed label: ci-pipeline-passedapi-check-pass
CANN-robotCANN-robotCollaborators
29 days ago Added label: ci-pipeline-running
CANN-robot
CANN-robotCollaborators
29 days ago Comments:

流水线任务触发成功
任务链接 [1ef54d0c1c50486ab2f87d5ae85f82b1][流水线指导]

任务名称状态日志下载链接
PreSmoke_ATK_Test_A2 ✅ SUCCESS >>>>>

[2026-10-10 00:11:24]    CI执行结束

likedislike
CANN-robot
CANN-robotCollaborators
29 days ago Comments:

流水线任务触发成功
任务链接 [d19a532fe7964610be12090fd6bc5179][流水线指导]

任务名称状态日志下载链接
Compile_Ascend_X86 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_single ✅ SUCCESS >>>>> >>>>>
pre_comment ✅ SUCCESS >>>>>
Compile_Ascend_X86_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_single_ubuntu24 ✅ SUCCESS >>>>> >>>>>
UT_Test_ophost ✅ SUCCESS
UT_Test_opapi ✅ SUCCESS
API_Check ✅ SUCCESS >>>>>

[2026-10-10 00:13:40]    CI执行结束

likedislike
CANN-robotCANN-robotCollaborators
29 days ago Added label: api-check-pass
CANN-robotCANN-robotCollaborators
29 days ago Removed label: api-check-pass
CANN-robot
CANN-robotCollaborators
29 days ago Comments:

流水线任务触发成功
任务链接 [1560d486ffbe4dd791a1128abc51919c][流水线指导]

任务名称状态日志下载链接
codecheck ✅ SUCCESS >>>>>
SCA ✅ SUCCESS >>>>>
antipoison ✅ SUCCESS >>>>>
codecheck_Pr ✅ SUCCESS
codecheck_codestyle ✅ SUCCESS >>>>>
codecheck_precommit ✅ SUCCESS >>>>>

[2026-10-10 00:19:06]    CI执行结束

likedislike
CANN-robotCANN-robotCollaborators
29 days ago Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
29 days ago Added label: ci-pipeline-passed
tianjun
23 hours ago Comments:

compile

likedislike
tianjun
23 hours ago Comments:

@loov1 @llimwang 您好,这个 PR 当前没有未解决的行内评审意见。上次 CI 已通过;因触发时间超过两天,已重新评论 compile 请求验证,当前等待本轮结果。烦请您方便时检视;若无其他问题,请按模块权限给予 /approve 和 /lgtm。若仍需调整,我会继续跟进。谢谢!

likedislike
CANN-robotCANN-robotCollaborators
23 hours ago Removed label: ci-pipeline-passed
CANN-robotCANN-robotCollaborators
23 hours ago Added label: ci-pipeline-running
CANN-robot
CANN-robotCollaborators
23 hours ago Comments:

流水线任务触发成功
任务链接 [cb00087818ee41e19f0df5b92d03b6ae][流水线指导]

任务名称状态日志下载链接
Compile_Ascend_X86 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_single ✅ SUCCESS >>>>> >>>>>
pre_comment ✅ SUCCESS >>>>>
Compile_Ascend_X86_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_single_ubuntu24 ✅ SUCCESS >>>>> >>>>>
UT_Test_ophost ✅ SUCCESS
UT_Test_opapi ✅ SUCCESS
API_Check ✅ SUCCESS >>>>>

[2026-11-08 00:12:00]    CI执行结束

likedislike
CANN-robot
CANN-robotCollaborators
23 hours ago Comments:

流水线任务触发成功
任务链接 [d7434ec693eb4a7d95d4f5792e621168][流水线指导]

任务名称状态日志下载链接
PreSmoke_ATK_Test_A2 ✅ SUCCESS >>>>>

[2026-11-08 00:10:45]    CI执行结束

likedislike
CANN-robotCANN-robotCollaborators
23 hours ago Added label: api-check-pass
CANN-robotCANN-robotCollaborators
23 hours ago Removed label: api-check-pass
CANN-robot
CANN-robotCollaborators
23 hours ago Comments:

流水线任务触发成功
任务链接 [5ea3cfe6a1a347079bff8a8ef48b3822][流水线指导]

任务名称状态日志下载链接
codecheck ✅ SUCCESS >>>>>
SCA ✅ SUCCESS >>>>>
antipoison ✅ SUCCESS >>>>>
codecheck_Pr ✅ SUCCESS
codecheck_codestyle ✅ SUCCESS >>>>>
codecheck_precommit ✅ SUCCESS >>>>>

[2026-11-08 00:14:06]    CI执行结束

likedislike
CANN-robotCANN-robotCollaborators
23 hours ago Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
23 hours ago Added label: ci-pipeline-passed