3 ms·
I like this one too as an example of what can be done to make a C FFI safe: https://bluishcoder.co.nz/2012/08/30/safer-handling-of-c-memory-in-ats.html https://
by doublec 10y ago
I like this one too as an example of what can be done to make a C FFI safe: https://bluishcoder.co.nz/2012/08/30/safer-handling-of-c-memory-in-ats.html https://bluishcoder.co.nz/2012/08/30/safer-handling-of-c-mem...
You end up with a definition that checks at compile time that:
* We don't exceed the memory bounds of the source buffer
* We don't exceed the memory bounds of the destination buffer
* The destination buffer is at least the minimium size required by the function documentation
* We can't treat the destination buffer as a string if the function fails
* We can't treat the destination buffer as an array of bytes if the function succeeds
* Off by one errors due to null terminator handling are removed
* Checking to see if the function call failed is enforced
And there's no overhead at runtime.