Skip to content

MIRAI fails to identify division-by-zero bug due to various types #35

@stoneman258

Description

@stoneman258

Issue

While using MIRAI to analyze a Rust project, I found that it fails to generate a division-by-zero warning for the isize type, whereas the u64 type correctly triggers such a warning.

Steps to Reproduce

The minimized test case with isize:

fn test(x: isize, y: isize) -> isize {
    x / y 
}
fn main() {
    test(1, 0);
}

The minimized test case with u64:

fn test(x: u64, y: u64) -> u64 {
    x / y 
}
fn main() {
    test(1, 0);
}

Then run cargo mirai in both test cases.

Expected Behavior

MIRAI should generate warning for both test case, as both case will panic with divided bu zero.

Actual Results

MIRAI only generates division zero warning in the second case.

warning: [MIRAI] attempt to divide by zero
 --> src/main.rs:5:5
  |
5 |     test(1, 0);
  |     ^^^^^^^^^^
  |
note: related location
 --> src/main.rs:2:5
  |
2 |     x / y
  |     ^^^^^

warning: `div_u64` (bin "div_u64") generated 1 warning
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.44s

Environment

Rust version (rustc --version)
rustc 1.86.0-nightly (824759493 2025-01-09)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions