3 ms·
I'm reminded of https://www.foonathan.net/2022/08/malloc-interface/#problem-4-realloc https://www.foonathan.net/2022/08/malloc-interface/#problem-.... While ini
by nyanpasu64 4y ago
I'm reminded of https://www.foonathan.net/2022/08/malloc-interface/#problem-4-realloc https://www.foonathan.net/2022/08/malloc-interface/#problem-.... While initially I was skeptical of the author's criticism of C's allocation APIs, this bug seems to be one that could've been avoided by using the proposed try_expand() instead of realloc().
Of course ideally we'd move away from provenance-based UB and Rust's third-class aliased mutability, to simpler conservative aliasing semantics by default, and allow programmers to opt into non-general optimizations by manually saving unchanging values like vector::size() into locals, or have the optimizer and programmer interactively explore code invariants and optimizations, making the optimizer a performance-focused pair programmer rather than a black box.