fix(narrow): File.write 长度实参加显式 ULONG(...)(避免 64→32 隐式窄化)

fileio.File.write(buf, count: ULONG) 的 count 是 32 位,而实参是 sizet/int64(strlen、pos、ir_len、total 等);规则收紧后为隐式窄化,改为显式 ULONG(...)。本文件其它位置无隐式窄化。
This commit is contained in:
TermiNexus committed 2026-10-10 22:10:01 +08:00
1 parent 5bb6538703
commit 58951a29a8
1 file changed
+7 -7
+7 -7
View File
@@ -131,7 +131,7 @@ def WriteCallSidecar(temp_dir: str, sha1: str, text: str) -> int:
VLogger.error(f"--traceback: failed to write .vpcall (cannot open {vpath}), aborting compilation", "TRACEBACK")
stdlib.free(vpath)
return 1
vf.write(text, string.strlen(text))
vf.write(text, ULONG(string.strlen(text)))
vf.close()
return _tb_register_vpcall(vpath)
@@ -199,7 +199,7 @@ def TranslateFileGetTrans(mb: memhub.MemBuddy*, file_path: str, sha1_val: str, c
if pyi_path is not None:
pf: fileio.File* = fileio.File(pyi_path, fileio.MODE.W)
if not pf.closed:
pf.write(pyi_buf, pyi_pos)
pf.write(pyi_buf, ULONG(pyi_pos))
pf.close()
stdlib.free(pyi_path)
stdlib.free(pyi_buf)
@@ -349,7 +349,7 @@ def write_ir_to_file(ir_buf: bytes, ir_len: sizet, output_dir: str, module_name:
f: fileio.File* = fileio.File(path, fileio.MODE.W)
if f.closed: return 1
written: int64 = f.write(ir_buf, ir_len)
written: int64 = f.write(ir_buf, ULONG(ir_len))
f.close()
if written < 0: return 1
return 0
@@ -553,9 +553,9 @@ def _phase2_write_cmd(cmd: str) -> None:
_phase2_bat_init = 1
hdr1: str = "@echo off\r\n"
hdr2: str = "rem TransPyV --phase2command generated commands\r\n"
f.write(hdr1, string.strlen(hdr1))
f.write(hdr2, string.strlen(hdr2))
f.write(cmd, string.strlen(cmd))
f.write(hdr1, ULONG(string.strlen(hdr1)))
f.write(hdr2, ULONG(string.strlen(hdr2)))
f.write(cmd, ULONG(string.strlen(cmd)))
f.write("\r\n", 2)
f.close()
@@ -2358,7 +2358,7 @@ def WriteStackMap(mb: memhub.MemBuddy*, exe_path: str) -> int:
if mf.closed:
VLogger.error(f"--traceback: failed to write sidecar file (cannot open {map_path}), aborting compilation", "TRACEBACK")
return 1
mf.write(out, total)
mf.write(out, ULONG(total))
mf.close()
VLogger.success(f"--traceback: wrote address-to-source-line sidecar {map_path} ({uniq} records, {total} bytes)", "TRACEBACK")
return 0