Repository navigation
Description
Problem
buffer_append detects sources inside its destination allocation so it can preserve their offset if buffer_reserve moves the allocation. The current membership check uses offset_value <= buf.cap, including the address immediately after the allocation.
A separate live allocation can begin at that address. Its first initialized byte is then misclassified as an internal source and rejected by the initialized-range check, even though the append is valid and the destination has enough capacity.
Code references:
- std/buffer/write.wave — buffer_append and buffer_append_buffer
- std/buffer/alloc.wave — buffer_init, buffer_is_valid, and buffer_reserve
Regression scenario
Arrange two separate, simultaneously live 16-byte allocations with no gap:
A.data = p, A.len = 0, A.cap = 16
B.data = p + 16, B.len = 1, B.cap = 16
B.data[0] = 0x41
buffer_append(&A, B.data, 1)
Here B.data is obtained from B's own allocation, not by dereferencing a one-past pointer derived from A. Expected: BUFFER_OK, A.len == 1, and A.data[0] == 0x41, with B unchanged.
Tracing the current source gives offset_value == 16. The <= A.cap condition selects the internal-source branch, and offset > A.len returns BUFFER_ERR_INVALID. This case needs no destination growth and isolates the allocation-boundary classification.
This is a false rejection of valid input; it does not establish a memory-corruption result.
Scope
Use the half-open allocation interval [data, data + cap) for internal-source classification. Retain the subtraction-based address comparison so the check does not require potentially overflowing end-address arithmetic.
Keep initialized-source bounds checks and offset recovery across growth for actual internal sources. External pointers remain subject to the caller's existing obligation to provide size readable initialized bytes.
Completion criteria
- A source from a separate live allocation beginning exactly at
data + capis accepted when the append otherwise satisfies the API contract. - Add an executable regression with deterministic adjacent allocations, such as a controlled allocator fixture or the existing WebAssembly allocation path after verifying the layout. Do not rely on host allocator luck or fabricated integer addresses.
- Check the returned status, destination length and bytes, and unchanged source contents.
- Preserve self-append and interior-slice append both with and without destination growth.
- Preserve rejection of internal sources that extend beyond initialized bytes, plus existing zero-length, invalid-buffer, overflow, and allocation-failure behavior.
- Keep the public API and allocator ownership rules unchanged; no libc binding or new external dependency is needed.
The adjacent-allocation scenario above describes the source-level failure path and the required runtime regression, not an already executed Wave test.
Activity
Fix numeric lowering and standard-library boundary handling (wavefnd#707