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

Fix potential overflow in FixedDiv, re-add gcc asm implementation #1832

Merged
merged 3 commits into from
Dec 7, 2024

Conversation

gendlin
Copy link
Contributor

@gendlin gendlin commented Aug 11, 2024

If the first argument of FixedDiv is INT_MIN its overflow check is effectively bypassed because abs(INT_MIN)==INT_MIN. This is the only possible explanation I can see for #1816, even though neither @rfomin nor myself have been able to reproduce this crash.

Using an unsigned comparison here fixes the problem and seems like it shouldn't affect demo compatibility - this bug has never been reported in game (see discussion here) so it seems impossible to get INT_MIN as either arg in the course of normal play or else someone would have noticed by now. Modern ports technically already broke compatibility here anyway - in vanilla an overflow will result in a crash, while an implementation using an int64 divide will silently return an incorrect truncated result instead.

@rfomin
Copy link
Collaborator

rfomin commented Aug 11, 2024

This is the only possible explanation I can see for #1816, even though neither @rfomin nor myself have been able to reproduce this crash.

It's hard to fix a bug if we can't reproduce it. Thanks, but I think we should merge this after the next release.

@rfomin rfomin merged commit 458c61a into fabiangreffrath:master Dec 7, 2024
8 checks passed
@rfomin
Copy link
Collaborator

rfomin commented Dec 7, 2024

Thank you!

fabiangreffrath pushed a commit that referenced this pull request Dec 7, 2024
)

* Revert "remove GCC variant of `div64_32` (#1818)"

This reverts commit fac7cf7.

* Remove asm multi-constraint

clang generates poor code otherwise:

https://stackoverflow.com/questions/16850309/clang-llvm-inline-assembly-multiple-constraints-with-useless-spills-reload

* Fix potential FixedDiv overflow when passed INT_MIN as first arg
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

Successfully merging this pull request may close these issues.

2 participants