code wiki / (root) / _offc_strlen_call.nx

_offc_strlen_call.nx source

↩ module page · 26 lines · 617 B

1// Mirror the parse_function pattern: 2// let name_ptr: *u8 = tok_text_ptr(name_tok) 3// var name_len: i64 = 0 4// while name_ptr[name_len] != 0 { name_len = name_len + 1 } 5// If this miscompiles, that's the next Bar 3 bug. 6 7import "syscalls.nx" 8 9func make_buf() -> *u8 { 10 let raw: *u8 = sys_mmap(16) 11 raw[0] = 65 // 'A' 12 raw[1] = 66 // 'B' 13 raw[2] = 67 // 'C' 14 raw[3] = 0 15 return raw 16} 17 18func main() -> i64 { 19 let p: *u8 = make_buf() 20 var n: i64 = 0 21 while p[n] != 0 { 22 n = n + 1 23 if n > 100 { return 99 } 24 } 25 return n // expect 3 26}