Repository navigation
Description
Problem
input accepts bool and wide integer destinations, but its scanf formats do not match their storage. A bool field is passed to %d, which writes beyond its one-byte storage and overwrites adjacent fields. A u128 destination uses %llu, leaving its upper half unchanged.
Relevant paths: front/parser/src/verification.rs and llvm/src/codegen/format.rs.
Reproduction
Save as repro.wave:
struct S { flag: bool; a: u8; b: u8; c: u8; }
fun main() -> i32 {
var s: S = S { flag: false, a: 65, b: 66, c: 67 };
input("{}", s.flag);
if (s.a != 65 || s.b != 66 || s.c != 67) { return 1; }
return 0;
}
target/release/wavec check repro.wave
target/release/wavec build repro.wave -O0 --emit=ir,obj,bin --out-dir /tmp/wave-audit-repro
printf '1\n' | /tmp/wave-audit-repro/reproRepeat with -O2. Tested on master 5002a93a4a233032553aa6c6e3639d88e93c53bf with Fedora Linux 43 amd64 and LLVM 21.1.8, using LLVM_SYS_211_PREFIX=/usr/lib64/llvm21 cargo build --locked --release --jobs 2.
With input 1, checking/building succeeds and execution returns 1 at both O0/O2: neighboring fields changed. Replacing flag: bool/false with flag: i32/0 returns 0. IR confirms %d receives the bool field address.
A second executed case initializes n: u128 = 18446744073709551616, reads 1 into it, and checks n == 1; it fails at O0/O2. Its IR uses %llu with the u128 address.
Scope
Audit every accepted input scalar width against the selected target ABI. Parse into suitably sized temporary storage when conversion is required, and write only the validated destination size. Maintainer-approved contract: bool input accepts only numeric 0 and 1, and every existing signed/unsigned integer width through 1024 bits must be parsed exactly. Other boolean values and out-of-range integer input must follow the input failure path without corrupting destination storage. No new libc FFI dependency is needed.
Completion criteria
- Boolean input accepts only 0 and 1 and cannot change neighboring bytes; other values fail.
- All supported integer widths through 1024 bits receive the complete intended value with range validation.
- Tests cover bool, narrow integers, 64-bit integers, wider integers, and normal failure paths at O0/O2.
- Include Windows MSVC width checks; preserve mutable-lvalue validation.
Activity