mirror of
https://github.com/lahfir/agent-desktop.git
synced 2026-08-06 06:00:39 +00:00
Closes P1 todo 001. Every enum-typed field that a foreign caller writes through the C ABI was previously stored as a Rust #[repr(i32)] enum — out-of-range bit patterns crossed the boundary before the enum_raw_i32 validator could catch them, invoking undefined behavior at the field read. The validator was directionally correct but fired too late. Switched to raw i32 storage on every externally supplied public ABI struct: - AdAction.kind - AdScrollParams.direction - AdMouseEvent.kind, .button - AdWindowOp.kind - AdTreeOptions.surface - AdScreenshotTarget.kind - AdKeyCombo.modifiers (was *const AdModifier, now *const i32) Every conversion site now reads the raw i32 directly and calls <Enum>::from_c(raw) — an invalid discriminant returns None, and the FFI entrypoint surfaces AD_RESULT_ERR_INVALID_ARGS without ever constructing an invalid enum value in Rust. Dropped the now-unused enum_raw_i32 helper and its test; replaced with a direct round-trip test that confirms <Enum> as i32 -> from_c -> Some(<Enum>) still holds for valid values. Updated unit-test AdAction / AdMouseEvent / AdScrollParams builders to use <Enum> as i32 casts. The c_abi_harness fuzz test simplifies — it no longer needs ptr::copy_nonoverlapping because the field is just i32. 63 FFI tests pass, clippy --all-targets clean, header regenerated. |
||
|---|---|---|
| .. | ||
| core | ||
| ffi | ||
| linux | ||
| macos | ||
| windows | ||