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 included psrand.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
[ ] GitHub Workflow changes
[ ] Documentation or Wiki changes
[x] Build and Dependency changes
[ ] Runtime changes
[ ] Render changes
[ ] Audio changes
[ ] Input changes
[ ] Network changes
[ ] Other changes
Description
When compiling D3, there are several overflow warning regarding RAND_MAX + 1 because the value of RAND_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 value 0x7FFFFFFFis 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 to 0x7FFF. The solution is to simply rename references to RAND_MAX that would be redefined (on a more forgiving compiler) from RAND_MAX to D3_RAND_MAX.
However, not all parts of the code that use RAND_MAX also include psrand.h which means the ISO RAND_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
[x] I have tested my changes locally and verified that they work as intended.
[x] I have documented any new or modified functionality.
[x] I have reviewed the changes to ensure they do not introduce any unnecessary complexity or duplicate code.
[x] I understand that by submitting this pull request, I am agreeing to license my contributions under the project's license.
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