miri | An interpreter for Rust 's mid-level intermediate

 by   rust-lang Rust Version: Current License: Apache-2.0

kandi X-RAY | miri Summary

kandi X-RAY | miri Summary

miri is a Rust library. miri has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. You can download it from GitHub.

An experimental interpreter for Rust's mid-level intermediate representation (MIR). It can run binaries and test suites of cargo projects and detect certain classes of undefined behavior, for example:. On top of that, Miri will also tell you about memory leaks: when there is memory still allocated at the end of the execution, and that memory is not reachable from a global static, Miri will raise an error.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              miri has a medium active ecosystem.
              It has 3259 star(s) with 258 fork(s). There are 48 watchers for this library.
              OutlinedDot
              It had no major release in the last 6 months.
              There are 103 open issues and 613 have been closed. On average issues are closed in 530 days. There are 7 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of miri is current.

            kandi-Quality Quality

              miri has 0 bugs and 0 code smells.

            kandi-Security Security

              miri has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              miri code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              miri is licensed under the Apache-2.0 License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              miri releases are not available. You will need to build from source code and install.
              Installation instructions are not available. Examples and code snippets are available.
              It has 153 lines of code, 7 functions and 1 files.
              It has low code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of miri
            Get all kandi verified functions for this library.

            miri Key Features

            No Key Features are available at this moment for miri.

            miri Examples and Code Snippets

            No Code Snippets are available at this moment for miri.

            Community Discussions

            QUESTION

            select only one checkbox react when they are mapped inputs
            Asked 2022-Apr-07 at 13:39

            so I am creating this table where I take the attendance of someone. I did a table when I show the players and give them false values by default. So I want to it be when you can select only one of the option, the person is present, missing, injured, sick or late.

            I saw some things like this but cant find something that truly helps or work fully

            this is the link to the code: https://stackblitz.com/edit/react-uwhyxm

            this is the code :

            ...

            ANSWER

            Answered 2022-Apr-07 at 13:39

            You can use input radio type. Use id as name for the input

            Source https://stackoverflow.com/questions/71782505

            QUESTION

            Why does peek return unexpected results in my circular linked list?
            Asked 2022-Mar-24 at 20:51

            I'm attempting to implement a circular linked list in Rust. I've read Too Many Linked Lists and multiple resources on the Rust Pin type, and I've attempted to build a circular linked list from scratch and I'm getting baffled at what the compiler spits out.

            So the high-level concept is I want a linked list struct and node struct defined as followed:

            ...

            ANSWER

            Answered 2022-Mar-16 at 01:55

            Warning: You should not write unsafe code unless you completely understand all details of it! (experimentation is fine, though).

            You got a Use-After-Free. At the end of enqueue(), the destructor of Box is executed for pinned_new_last and frees its memory. Now your linked list points to freed node. Adding std::mem::forget() is enough in this case:

            Source https://stackoverflow.com/questions/71490876

            QUESTION

            not returning anything although there is no problem public static int
            Asked 2021-Nov-07 at 16:20

            I got homework to do where I need to make it return 1 if sum is bigger or equals to 2 and 0 otherwise. But it's not returning anything.

            Thanks for help. Here is the program:

            ...

            ANSWER

            Answered 2021-Nov-07 at 16:20

            You never called twoOrLess, so you just call it from your main.

            twoOrLess does not get called automatically like main. You have to call twoOrLess.

            EDIT

            Source https://stackoverflow.com/questions/69873969

            QUESTION

            Initializing a struct field-by-field. Is it possible to know if all the fields were initialized?
            Asked 2021-Sep-22 at 20:30

            I'm following the example from the official documentation. I'll copy the code here for simplicity:

            ...

            ANSWER

            Answered 2021-Sep-21 at 21:46

            I believe MaybeUninit is designed for the cases when you have all the information about its contents and can make the code safe "by hand".

            If you need to figure out in runtime if a field has a value, then use Option.

            Per the documentation:

            You can think of MaybeUninit as being a bit like Option but without any of the run-time tracking and without any of the safety checks.

            Source https://stackoverflow.com/questions/69274252

            QUESTION

            Q: How to exclude persons name from a table
            Asked 2021-Jun-25 at 14:17

            I am trying to use bigquery to find the 10 most mentioned persons in 4 Israeli news websites via gdeltv2 dataset. I succeded getting the 10 most mentioned persons and now I want to exclude two persons from the top 10 list, 'Maccabi Haifa ' and 'Reuben Castro '. I am using standardSQL bigqury code.

            I created the dataset with this code:

            ...

            ANSWER

            Answered 2021-Jun-25 at 06:48

            Just replace OR with AND in WHERE person <> 'Maccabi Haifa ' OR person <> 'Reuben Castro ':

            Source https://stackoverflow.com/questions/68126560

            QUESTION

            Polymorphic update on struct fields in Rust
            Asked 2021-Mar-03 at 16:48

            Suppose I have a polymorphic type T:

            ...

            ANSWER

            Answered 2021-Mar-03 at 16:48

            You're confusing yourself with the whole T stuff. This should be much easier to analyze. Specifically, read here.

            Source https://stackoverflow.com/questions/66457845

            QUESTION

            Is it undefined behavior to mutate an immutable local variable?
            Asked 2021-Feb-02 at 13:09

            The Rust Reference seems to say that mutating an immutable local data (that's not inside an UnsafeCell) is undefined behavior:

            Behavior considered undefined
            • Mutating immutable data. All data inside a const item is immutable. Moreover, all data reached through a shared reference or data owned by an immutable binding is immutable, unless that data is contained within an UnsafeCell.

            The following code mutates an immutable local variable by reinterpreting it as an AtomicU32. Currently the code runs just fine and prints the expected result, but is its behavior actually undefined?

            ...

            ANSWER

            Answered 2021-Feb-01 at 19:35

            Yes, according to Miri:

            Source https://stackoverflow.com/questions/65997647

            QUESTION

            Why does Box::from_raw work with a pointer to slice data when the slice is not empty?
            Asked 2020-Jul-03 at 06:38

            I wrote some Rust code that provides a FFI for some C code, which I recently discovered a bug in. Turns out unsafe is hard and error prone — who knew! I think I've fixed the bug but I am curious to understand the issue more.

            One function took a Vec, called into_boxed_slice on it and returned the pointer (via as_mut_ptr) and length to the caller. It called mem:forget on the Box before returning.

            The corresponding "free" function only accepted the pointer and called Box::from_raw with it. Now this is wrong, but the amazing thing about undefined behaviour is that it can work most of the time. And this did. Except if the source Vec was empty when it would segfault. Also of note, MIRI correctly identifies the issue: "Undefined Behavior: inbounds test failed: 0x4 is not a valid pointer".

            Anyway the fix was to take the length in the free function as well, reconstitute the slice, then Box::from_raw that. E.g. Box::from_raw(slice::from_raw_parts_mut(p, len))

            I've tried to capture all of this in this playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=7fe80cb9f0c5c1eee4ac821e58787f17

            Here's the playground code for reference:

            ...

            ANSWER

            Answered 2020-Jul-03 at 06:38

            That's because when you deconstruct your empty vector, you get a null pointer and a zero length.

            When you call Box::from_raw (null), you break one of the box invariants: "Box values will always be fully aligned, non-null pointers". Then when Rust drops the box, it attempts to deallocate the null pointer.

            OTOH when you call slice::from_raw_parts, Rust allocates a new fat pointer that contains the null pointer and the zero length, then Box::from_raw stores a reference to this fat pointer in the Box. When dropping the box, Rust first drops the slice (which knows that a length of zero means a null data that doesn't need to be freed), then frees the memory for the fat pointer.

            Note also that in the non-working case you reconstruct a Box, whereas in the working case you reconstruct a Box<[i32]>, as shown if you try to compile the following code:

            Source https://stackoverflow.com/questions/62708492

            QUESTION

            Writing to a field in a MaybeUninit structure?
            Asked 2020-Apr-20 at 14:21

            I'm doing something with MaybeUninit and FFI in Rust that seems to work, but I suspect may be unsound/relying on undefined behavior.

            My aim is to have a struct MoreA extend a struct A, by including A as an initial field. And then to call some C code that writes to the struct A. And then finalize MoreA by filling in its additional fields, based on what's in A.

            In my application, the additional fields of MoreA are all integers, so I don't have to worry about assignments to them dropping the (uninitialized) previous values.

            Here's a minimal example:

            ...

            ANSWER

            Answered 2020-Apr-20 at 14:20

            Currently, the only sound way to refer to uninitialized memory—of any type—is MaybeUninit. In practice, it is probably safe to read or write to uninitialized integers, but that is not officially documented. It is definitely not safe to read or write to an uninitialized bool or most other types.

            In general, as the documentation states, you cannot initialize a struct field by field. However, it is sound to do so as long as:

            1. the struct has repr(C). This is necessary because it prevents Rust from doing clever layout tricks, so that the layout of a field of type MaybeUninit remains identical to the layout of a field of type T, regardless of its adjacent fields.
            2. every field is MaybeUninit. This lets us assume_init() for the entire struct, and then later initialise each field individually.

            Given that your struct is already repr(C), you can use an intermediate representation which uses MaybeIninit for every field. The repr(C) also means that we can transmute between the types once it is initialised, provided that the two structs have the same fields in the same order.

            Source https://stackoverflow.com/questions/61318595

            QUESTION

            Does std::ptr::write transfer the "uninitialized-ness" of the bytes it writes?
            Asked 2020-Apr-11 at 18:04

            I'm working on a library that help transact types that fit in a pointer-size int over FFI boundaries. Suppose I have a struct like this:

            ...

            ANSWER

            Answered 2020-Apr-11 at 18:04

            Does that assume_init call triggered undefined behavior?

            Yes. "Uninitialized" is just another value that a byte in the Rust Abstract Machine can have, next to the usual 0x00 - 0xFF. Let us write this special byte as 0xUU. (See this blog post for a bit more background on this subject.) 0xUU is preserved by copies just like any other possible value a byte can have is preserved by copies.

            But the details are a bit more complicated. There are two ways to copy data around in memory in Rust. Unfortunately, the details for this are also not explicitly specified by the Rust language team, so what follows is my personal interpretation. I think what I am saying is uncontroversial unless marked otherwise, but of course that could be a wrong impression.

            Untyped / byte-wise copy

            In general, when a range of bytes is being copied, the source range just overwrites the target range -- so if the source range was "0x00 0xUU 0xUU 0xUU", then after the copy the target range will have that exact list of bytes.

            This is what memcpy/memmove in C behave like (in my interpretation of the standard, which is not very clear here unfortunately). In Rust, ptr::copy{,_nonoverlapping} probably performs a byte-wise copy, but it's not actually precisely specified right now and some people might want to say it is typed as well. This was discussed a bit in this issue.

            Typed copy

            The alternative is a "typed copy", which is what happens on every normal assignment (=) and when passing values to/from a function. A typed copy interprets the source memory at some type T, and then "re-serializes" that value of type T into the target memory.

            The key difference to a byte-wise copy is that information which is not relevant at the type T is lost. This is basically a complicated way of saying that a typed copy "forgets" padding, and effectively resets it to uninitialized. Compared to an untyped copy, a typed copy loses more information. Untyped copies preserve the underlying representation, typed copies just preserve the represented value.

            So even when you transmute 0usize to PaddingDemo, a typed copy of that value can reset this to "0x00 0xUU 0xUU 0xUU" (or any other possible bytes for the padding) -- assuming data sits at offset 0, which is not guaranteed (add #[repr(C)] if you want that guarantee).

            In your case, ptr::write takes an argument of type PaddingDemo, and the argument is passed via a typed copy. So already at that point, the padding bytes may change arbitrarily, in particular they may become 0xUU.

            Uninitialized usize

            Whether your code has UB then depends on yet another factor, namely whether having an uninitialized byte in a usize is UB. The question is, does a (partially) uninitialized range of memory represent some integer? Currently, it does not and thus there is UB. However, whether that should be the case is heavily debated and it seems likely that we will eventually permit it.

            Many other details are still unclear, though -- for example, transmuting "0x00 0xUU 0xUU 0xUU" to an integer may well result in a fully uninitialized integer, i.e., integers may not be able to preserve "partial initialization". To preserve partially initialized bytes in integers we would have to basically say that an integer has no abstract "value", it is just a sequence of (possibly uninitialized) bytes. This does not reflect how integers get used in operations like /. (Some of this also depends on LLVM decisions around poison and freeze; LLVM might decide that when doing a load at integer type, the result is fully poison if any input byte is poison.) So even if the code is not UB because we permit uninitialized integers, it may not behave as expected because the data you want to transfer is being lost.

            If you want to transfer raw bytes around, I suggest to use a type suited for that, such as MaybeUninit. If you use an integer type, the goal should be to transfer integer values -- i.e., numbers.

            Source https://stackoverflow.com/questions/61114026

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install miri

            You can download it from GitHub.
            Rust is installed and managed by the rustup tool. Rust has a 6-week rapid release process and supports a great number of platforms, so there are many builds of Rust available at any time. Please refer rust-lang.org for more information.

            Support

            If you want to contribute to Miri, great! Please check out our contribution guide. For help with running Miri, you can open an issue here on GitHub or use the Miri stream on the Rust Zulip.
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/rust-lang/miri.git

          • CLI

            gh repo clone rust-lang/miri

          • sshUrl

            git@github.com:rust-lang/miri.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link

            Consider Popular Rust Libraries

            996.ICU

            by 996icu

            deno

            by denoland

            rust

            by rust-lang

            alacritty

            by alacritty

            tauri

            by tauri-apps

            Try Top Libraries by rust-lang

            rust

            by rust-langRust

            rustlings

            by rust-langRust

            mdBook

            by rust-langRust

            book

            by rust-langRust

            rust-analyzer

            by rust-langRust