4 ms·
My friend suggest as the 64-bit address space is so big you could just throw out random numbers and get a working 'wrong' malloc. void* malloc(size_t sz) {
by hornetblack 13y ago
My friend suggest as the 64-bit address space is so big you could just throw out random numbers and get a working 'wrong' malloc.
void* malloc(size_t sz) {
return rand() << 32 | rand();
}
Or in rustopia:
fn extern "C" malloc(len: uint) -> *mut u8 {
unsafe {
std::rand::random::<uint>() as *mut u8;
}
}
Insert more so that it actually maps to memory.
- kabdib 13y agoIn fact, with a sufficiently large address space, you can prove that a "random" return value for malloc() is more reliable than a correct implementation, because of the likelihood that a machine failure would return a "bad" (collision) result when running the longer code path of the correct implementation. 256 bit addresses, anyone? Well, maybe 1024... :-)