[0144] C++ 层为 g_rename 增加参数类型检查,修复非字符串参数导致的段错误 - #965
Merged
Merged
Conversation
This was referenced Sep 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
(g_rename 1 2)会让 bin/gf 段错误(SIGSEGV, exit 139),见demo/crash/c09-g_rename-integer.scm。根因:
src/liii_os.cpp的f_rename直接s7_string(s7_car(args)),对非字符串对象等同于把对象强转为字符串 cell 解引用,垃圾指针传入std::filesystem::rename触发段错误。修复
沿用 #963(devel/0142.md)的模式,防御放在 C++ 层:
f_rename入口对src、dst分别检查s7_is_string,非字符串返回s7_wrong_type_arg_error。(liii os)公开包装rename已有string?检查,本修复使根环境直接调用g_rename的代码也受保护。测试
tests/liii/os/rename-test.scm增加 3 条 C 层入口回归测试。TDD:修复前运行测试文件本身即段错误(exit 139),修复后 12/12 通过(g_rename 1 2)由 SIGSEGV 变为干净的wrong-type-arg报错(exit 255),验证后按惯例移除demo/crash/c09-g_rename-integer.scm并更新 README备注
devel/0144.md