Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In
psrand.h
it attempts to undefine RAND_MAX and then define it once again. This may work on some compilers but not G++/Clang. To resolve this error RAND_MAX was renamed to D3_RAND_MAX but only in files.cpp
that includedpsrand.h
. The code behavior should restored to that of the official release.NOTE: Not every overflow is fixed because as far as I can tell, that's how it is in the official release as
psrand.h
is not included everywhere RAND_MAX is used.Pull Request Type
Description
When compiling D3, there are several overflow warning regarding
RAND_MAX + 1
because the value ofRAND_MAX
contains the same as INT32_MAX (0x7FFFFFFF
). However,psrand.h
does#undef RAND_MAX
and then defines it as 0x7FFF. This does not work with G++ and Clang and the value0x7FFFFFFF
is retained. Since compilers assume a given value is a signed integer (unless specified otherwise) adding one will cause an overflow and thus causing a overflow warning. This is a sign that the value of RAND_MAX was not redefined to0x7FFF
. The solution is to simply rename references toRAND_MAX
that would be redefined (on a more forgiving compiler) fromRAND_MAX
toD3_RAND_MAX
.However, not all parts of the code that use
RAND_MAX
also includepsrand.h
which means the ISORAND_MAX
value was likely used in the official release. This is why some overflow warnings will still persist after this patch.Related Issues
Screenshots (if applicable)
Checklist
Additional Comments