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

When validating integers, validate for overflow as well #82

Open
crankycyclops opened this issue Feb 25, 2022 · 1 comment
Open

When validating integers, validate for overflow as well #82

crankycyclops opened this issue Feb 25, 2022 · 1 comment

Comments

@crankycyclops
Copy link
Owner

When I validate integers, I should also validate for overflow (make sure the value represented in the string isn't larger than what can actually be stored in the data type.) That means I should have versions of this function that check for 32 as well as 64-bit integers, and both signed and unsigned for each.

@crankycyclops
Copy link
Owner Author

To check for overflow, I just need to do this:

    try {
        auto value = std::stoi("999999999999999999999999999");
    }
    catch (const std::out_of_range&) {
      ...
    }

Also, I need to write an isValidUnsigned* family of functions as well. When I do, revsisit my validation of SET_TIMER_PERIOD in instantiator.cpp.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant