4 comments

  • landr0id15 minutes ago
    If you have a codebase that uses unsafe, I highly recommend running your tests through Miri (cargo miri nextest) and seeing what spills out.<p>I ran tests for a codebase at work through Miri a while ago and found a couple of distinct classes of UB: <a href="https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;miri&#x2F;issues&#x2F;1807#issuecomment-845425076" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;miri&#x2F;issues&#x2F;1807#issuecomment-8...</a><p>These can be summarized as:<p>1. Converting a reference to the first field of a struct to a pointer of its parents struct type<p>2. Functions with signature (&amp;self) -&gt; &amp;mut self_inner_field_type<p>3. Having a mut pointer to the data inside of a Box&lt;T&gt;<p>#1 and #3 were somewhat surprising to me. #2 seems to be common enough that there&#x27;s even a clippy lint for it.<p>A lot of C and C++ developers understand that undefined behavior is bad, but in practice observe its impact less. From my own experience, Rust&#x27;s optimizations are pretty aggressive and tend to surface UB in way more observable ways than in C or C++.
  • mmastrac13 minutes ago
    I used Miri for some key deno libraries and spent a fair bit of time cleaning up the violations. Many of them were real unsoundness bugs due to reference aliasing.<p>Unsafe code absolutely needs Miri if the code paths are testable. If not all code is Miri-compatible, it&#x27;s worth restructuring it so you can Miri test as much as possible.<p>Note that Miri, Valgrid and the LLVM sanitizers all compliment each other and it&#x27;s really worth adding all of them to a project if you can.
  • nu11ptr46 minutes ago
    Thank you to those who continue to develop Miri. It is a great tool for those of us that have crates that need to use unsafe. While nothing will give 100% confidence in the lack of UB, Miri is a great start.
  • sleeplessworld43 minutes ago
    I have just been subjected to a Paradox Exception caused by reading that the memory safe Rust language has and can cause undefined behaviour. My spatial location code in the Universe has been marked with a Time-Space::Paradox violation and is awaiting debugging by celestial dev-ops. Luckily I am currently a live process, so my space and memory will not at this time be reclaimed by the Global-Universal Operating System.
    • nu11ptr37 minutes ago
      &gt; by reading that the memory safe Rust language has and can cause undefined behaviour<p>Only unsafe blocks can cause undefined behavior. The memory safe portion of Rust that most program in cannot cause UB. If you use &quot;forbid unsafe&quot; then you can be assured your program is free from UB (assuming all the crates and stdlib you use are as well).
      • sleeplessworld2 minutes ago
        It still leaves me lingering in a space-time-continuum where I search for the safety of rational completeness, while inadvertently living on a Möbious strip.