3 ms·
> If only we could guarantee immediate segfaults. It should be possible to create a malloc implementation that does that by making the minimum allocation size
by zrm 8y ago
> If only we could guarantee immediate segfaults.
It should be possible to create a malloc implementation that does that by making the minimum allocation size a page and then not reusing virtual addresses for new allocations. Then once an allocation is freed, any access to it is permanently a segfault.
That may not be practical on existing architectures with 48-bit virtual addressing though, since you could plausibly exhaust the address space. The full 64 bits might be sufficient for most things at least.
You could also get most of the benefit by not reusing virtual addresses until you run out.
- steveklabnik 8y agoIt's not, because that relies on actually doing the de-reference. Thanks to UB, that may never actually happen, the code may get removed entirely.
- zrm 8y agoIf the code is removed entirely then what memory is being improperly accessed?
- steveklabnik 8y agoIt's impossible to tell, as that can cause other issues. See the link I posted about time travel elsewhere in the thread.
- zrm 8y agoThe day will come when the compilers that do things like that will be righteously categorized as malware.
- the_why_of_y 8y agoThe day will come when language specifications that allow compilers to do things like that will be righteously categorized as archaic.