chore(gentype): ctypedef attr 手动逐字节检查(防 strcmp 读穿崩),定位内容损坏与读越界
This commit is contained in:
1 parent
7178d169e3
commit
8db5dc63a5
1 file changed
+13
-1
@@ -142,9 +142,21 @@ class TypeGenCType(TypeGenBase.TypeGenBase):
|
||||
# TypeGenCType 直接访问 at.attr 可能按 stub 类型生成错误 GEP,
|
||||
# 读垃圾地址 → strcmp 0xC0000005 崩溃,stdint.vp 根因)。
|
||||
at_attr_v: str = ast.attribute_get_attr(at)
|
||||
stdio.printf("[DIAG] ctypedef 检查: attr=%llu\n", t.CUInt64T(at_attr_v))
|
||||
# 诊断(stdint.vp strcmp 崩溃定位):手动逐字节检查 attr 前缀,
|
||||
# 避免 strcmp 读穿崩(attr 内容损坏/无 NUL 结尾)。prefix=1 表示
|
||||
# 内容正确('C''T''y''p'),则 strcmp 崩是读越界;=0 表示内容垃圾。
|
||||
attr_ok_d: int = 0
|
||||
if at_attr_v is not None:
|
||||
if at_attr_v[0] == 'C' and at_attr_v[1] == 'T' \
|
||||
and at_attr_v[2] == 'y' and at_attr_v[3] == 'p':
|
||||
attr_ok_d = 1
|
||||
stdio.printf("[DIAG] ctypedef 检查: attr=%llu prefix=%d\n",
|
||||
t.CUInt64T(at_attr_v), attr_ok_d)
|
||||
if at_attr_v is None:
|
||||
return 0
|
||||
if attr_ok_d == 0:
|
||||
# 内容损坏:跳过 strcmp(防读穿崩),返回 0(非 CTypedef)
|
||||
return 0
|
||||
if string.strcmp(at_attr_v, "CTypedef") != 0:
|
||||
return 0
|
||||
at_val_v: ast.AST | t.CPtr = ast.attribute_get_value(at)
|
||||
|
||||
Reference in new issue
Block a user