code wiki / (root) / nx_fix_putn.nx

nx_fix_putn.nx

buildroot/runtime/nx_fix_putn.nx

6798 B116 linesdepth 6pulls 6 transitivereach 0 importersview sourcekind tooltopic fix
docsdependenciesstructsconstsfunctions

about

nx_fix_putn.nx -- AUTO-FIXER for the propagating leaky-putn anti-pattern (per-character sys_mmap(1) inside a digit-print loop = a mmap-in-loop leak-by-construction, copied into ~40 fetch/census/gate organs). Replaces the exact leaky block with the hoisted write-once form -- BYTE-EXACT match, so a variant that doesn't match is left untouched (safe: never a fuzzy edit). Modes: nx_fix_putn <file> -- fix one file (report FIXED / no-match) nx_fix_putn sweep <dir> -- walk dir, fix every matching .nx, report count After fixing, the caller re-gates/rebuilds (the fix is proven verdict-equal to the 3 hand-fixes). This is the "build the tool so eating the debt is one step" move. Sovereign (getdents64 + file IO, no shell). expect_exit: 0

dependencies 2 imports · 0 importers

nx_syscalls.nx nx_dir.nx nx_fix_putn.nx

imports: nx_syscalls.nxnx_dir.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main fx_puts sys_write sys_exit sys_mmap nx_dir_list nx_openat nx_dirent_read nx_dirent_iter nx_dir_is_dotlike nx_dir_name_strlen nx_dir_arena_copy_name fx_fix_file fx_read sys_openat_rd sys_read sys_close fx_find fx_slen fx_slen ↻ sys_openat_wr sys_write ↻ sys_close ↻ fx_putn sys_write ↻ sys_mmap ↻

structs

none

consts

11const FX_MAGIC_4096: i64 = 4096
13const FX_BUF: i64 = 1048576
14const FX_CAP: i64 = 16384
19const FX_NEEDLE: *u8 = " var i: i64 = k - 1\x0a while i >= 0 { let o: *u8 = sys_mmap(1); o[0] = d[i]; sys_write(1, o, 1); i = i - 1 }\x00"
21const FX_REPL: *u8 = " let o: *u8 = sys_mmap(24); var i: i64 = 0\x0a while i < k { o[i] = d[k - 1 - i]; i = i + 1 }\x0a sys_write(1, o, k)\x00"

functions

23func fx_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
called by 1: main calls 1: sys_write
24func fx_putn(v: i64) -> i64
called by 1: main calls 2: sys_writesys_mmap
31func fx_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
called by 2: fx_findfx_fix_file
32func fx_read(path: *u8, buf: *u8) -> i64
39func fx_find(buf: *u8, n: i64, needle: *u8) -> i64
called by 1: fx_fix_file calls 1: fx_slen
51func fx_fix_file(path: *u8, buf: *u8, out: *u8) -> i64
70func main(argc: i64, argv: *i64) -> i64