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

Are checked adds necessary? #5

Open
jrozner opened this issue Jun 25, 2022 · 0 comments
Open

Are checked adds necessary? #5

jrozner opened this issue Jun 25, 2022 · 0 comments
Labels
question Further information is requested

Comments

@jrozner
Copy link
Owner

jrozner commented Jun 25, 2022

There are a number of places where the address is added to an offset (symbolic address mode, jxx instructions, etc.) There's already been one issue discovered and fixed caused by bad casting + arithmetic that caused an i16 MAX_I16 overflow during computation. Checked add is probably the correct way to make sure at runtime that nothing bad happens but since we're casting up to i64 to do math and both values are at most MAX_I16 or MAX_U16 there should be plenty of space to work with. If it's found to not be true the following is probably the correct way to handle it:

let val = ((addr as i64).checked_add(*i as i64)).unwrap_or(0) as u64;
@jrozner jrozner added the question Further information is requested label Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant