Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bad comparison of upcasted values #42

Closed
llogiq opened this issue May 3, 2015 · 5 comments
Closed

bad comparison of upcasted values #42

llogiq opened this issue May 3, 2015 · 5 comments
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy T-middle Type: Probably requires verifiying types

Comments

@llogiq
Copy link
Contributor

llogiq commented May 3, 2015

E.g. let x : u8 = ...; x as u32 > 300 maybe check sign of casted previously unsigned values.

@Manishearth Manishearth added good-first-issue These issues are a good way to get started with Clippy T-middle Type: Probably requires verifiying types A-lint Area: New lints labels Aug 11, 2015
@creativcoder
Copy link

I would like to work on this. Can you please elaborate more about this issue ?

@Manishearth
Copy link
Member

So here we need to check for situations where we are casting before comparing, i.e. x as u32 > 200 or x as u32 < 0, and the original type has a range such that the comparison will always be true or always be false.

...actually, this isn't really an easy bug since you have to look up the value of x and ensure its not getting written to.

@Manishearth
Copy link
Member

#97 should be easier. Its a simple check_ty with most of the details explained in the last comment. There are some complications there but I'll explain how to handle them when we reach that stage.

@llogiq
Copy link
Contributor Author

llogiq commented Aug 16, 2015

I don't think so. It should suffice matching a comparison where one of the operands is an ExprCast whose inner expression has a primitive type that is smaller than the comapred value (via expr_ty)

@Manishearth
Copy link
Member

Ah, I misunderstood the issue. In that case this isn't too hard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy T-middle Type: Probably requires verifiying types
Projects
None yet
Development

No branches or pull requests

4 participants