Re:The Rust Libs Blitz
by eridius on Friday May 05, 2017 @04:58PM
(#14276798)
Sounds to me like the unsafe block had the wrong scope. If safe Rust called a function with a buffer, and that buffer was too small, and that function internally used unsafe code to write to the buffer, then that function is leaking the unsafety past the `unsafe {}` scope, which is incorrect. So that function should be marked as `unsafe`, and the calling code (which calculates the buffer) is then responsible for ensuring that it's invoking the unsafe function with an appropriately-sized buffer.
[ Parent
| on HN ]
Re:The Rust Libs Blitz
by Manishearth on Friday May 05, 2017 @05:24PM
(#14276945)
Not necessarily. This isn't a question with a single answer within the community; there are reasons to tightly scope unsafe, and there are reasons to scope it to the full extent of unsafe-affecting invariants.
Scope your unsafe however you want, but check the invariants when auditing, and make sure they don't escape the module.