[HN Gopher] Passing nothing is surprisingly difficult
___________________________________________________________________
Passing nothing is surprisingly difficult
Author : kingkilr
Score : 33 points
Date : 2024-01-16 13:45 UTC (9 hours ago)
(HTM) web link (davidben.net)
(TXT) w3m dump (davidben.net)
| cbarrick wrote:
| Useful context on the Rust side is this issue [1]. It sounds like
| some of the author's concerns are addressed already.
|
| [1]: https://github.com/rust-lang/unsafe-code-
| guidelines/issues/4...
| steveklabnik wrote:
| see also
| https://www.reddit.com/r/rust/comments/19871c5/passing_nothi...
| SonOfLilit wrote:
| What a wonderfully subtle issue.
| kevingadd wrote:
| A fun additional twist to this is that dereferencing nullptr is
| valid in WebAssembly, and actual data can in fact end up there,
| though ideally it never will.
|
| If you ensure that the 'zero page' (so to speak) is empty you can
| also exploit this property for optimizations, and in some cases
| the emscripten toolchain will do so.
|
| i.e. if you have struct MyArray<T> { uint
| length; T items[0]; }
|
| you can elide null pointer checks and just do a single direct
| bounds check before dereferencing an element, because for a
| nullptr, (&ptr->length) == nullptr, and if you reserve the zero
| page and keep it empty, (nullptr)->length == 0.
|
| this complicates the idea of 'passing nothing' because now it is
| realistically possible for your code to get passed nullptr on
| purpose and it might be expected to behave correctly when that
| happens, instead of asserting or panicking like it would on other
| (sensible) targets
___________________________________________________________________
(page generated 2024-01-16 23:00 UTC)