Skip to content
This repository has been archived by the owner on Aug 23, 2024. It is now read-only.

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant