-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
prevent stored cal integer overflow #63849
prevent stored cal integer overflow #63849
Conversation
You need to check if A simple test case would be nice to have, too. |
shouldn't the std::abs do that anyways? if it overflows it will be -2147483647 which will correct it to a positive value, which is larger than the 2147000000 and thus min will reduce it to 2147000000. right? |
There's one more negative number because positive numbers start at 0, so you could get undefined behavior. You could also end up with less calories than before if you do it this way, which might not be the biggest concern, but it's weird behavior anyway. |
Signed overflow is actually undefined by the standard, so it's best to check if it would overflow here. |
I'll allow myself to voice an opinion as a normal contributor; |
Co-authored-by: Kevin Granade <[email protected]>
Summary
Bugfixes "stored calories cap instead of integer overflowing"
Purpose of change
Fixes #63727
Describe the solution
Simply limit max stored calories in the function that adjusts stored calories.
Should go along just fine with #60597.
Describe alternatives you've considered
Testing
Compiled and tested this by setting stored kcal to 2 million and guts kcal to 2 million and didn't see stored kcal exceed ~2.14 million after waiting over 24 hours repeatedly refreshing guts kcal to 2 million whenever it fell below 1 million kcal.
Additional context