Skip to content

Lint to disallow unsigned subtraction #45

@ppershing

Description

@ppershing

Lint explanation

Unsigned subtraction is likely to introduce underflow bugs. These bugs won't be caught in release mode.

Example code

Lint should disallow following code

let len: usize = vec.len();
let max_len: usize = 1000;
let available_space = max_len - len; // likely to underflow

while allowing both

let space = max_len.wrapping/saturating/checked_sub(len)

and

let len: isize = vec.len() as i32;
let max_len: isize = 1000;
let space = max_len - len;

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-user-storyArea: A user story or a related issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions