From f5624e91f1236eecb263f28600ce7f4b2fda149f Mon Sep 17 00:00:00 2001 From: Spencer Brower Date: Fri, 3 Jul 2026 21:42:13 -0400 Subject: [PATCH] perf: Added `#no_bounds_check` to ssh parsers. --- TODOS.md | 1 - ssh.odin | 16 +++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/TODOS.md b/TODOS.md index 9722f64..7449176 100644 --- a/TODOS.md +++ b/TODOS.md @@ -16,7 +16,6 @@ 8. Add tests for untested commands. -9. Audit ssh.odin for places where `#no_bounds_check` would be appropriate. ## Double-check AI output diff --git a/ssh.odin b/ssh.odin index 147e4e4..3c1b179 100644 --- a/ssh.odin +++ b/ssh.odin @@ -164,20 +164,26 @@ is_ed25519_key :: proc( return ok, nil } -read_wire_string :: proc(data: ^[]u8) -> (s: []u8, ok: bool) { - if len(data^) < 4 do return +read_wire_string :: proc(data: ^[]u8) -> (s: []u8, ok: bool) #no_bounds_check { + if len(data^) < 4 { + return + } length := endian.get_u32(data^[:4], .Big) or_return data^ = data^[4:] - if len(data^) < int(length) do return + if len(data^) < int(length) { + return + } s = data^[:int(length)] data^ = data^[int(length):] ok = true return } -read_wire_u32 :: proc(data: ^[]u8) -> (v: u32, ok: bool) { - if len(data^) < 4 do return +read_wire_u32 :: proc(data: ^[]u8) -> (v: u32, ok: bool) #no_bounds_check { + if len(data^) < 4 { + return + } v = endian.get_u32(data^[:4], .Big) or_return data^ = data^[4:] ok = true