Skip to content

[ZH] Fix level 1 compiler warnings for implicit integer type conversions and uninitialized variables in copy constructors #534

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

Closed

Conversation

roossienb
Copy link

Safely fixes about 2,500 warnings
Partially resolves #503

@DevGeniusCode DevGeniusCode added Build Anything related to building, compiling ZeroHour Relates to Zero Hour labels Mar 28, 2025
@Mauller Mauller changed the title Fixes Level 1 warnings for Zero hour [ZH] Fixes Level 1 warnings for Zero hour Mar 28, 2025
Copy link

@xezon xezon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull numbers in the commit titles are wrong.

@roossienb

This comment was marked as resolved.

roossienb pushed a commit to roossienb/GeneralsGameCode that referenced this pull request Mar 29, 2025
roossienb pushed a commit to roossienb/GeneralsGameCode that referenced this pull request Mar 29, 2025
roossienb pushed a commit to roossienb/GeneralsGameCode that referenced this pull request Mar 29, 2025
roossienb pushed a commit to roossienb/GeneralsGameCode that referenced this pull request Mar 29, 2025
roossienb pushed a commit to roossienb/GeneralsGameCode that referenced this pull request Mar 29, 2025
@roossienb roossienb force-pushed the fix/zh/warnings-level-1 branch from 916e6d6 to f05537e Compare March 29, 2025 21:33
roossienb pushed a commit to roossienb/GeneralsGameCode that referenced this pull request Mar 29, 2025
roossienb pushed a commit to roossienb/GeneralsGameCode that referenced this pull request Mar 29, 2025
@roossienb roossienb force-pushed the fix/zh/warnings-level-1 branch from f05537e to add6c02 Compare March 29, 2025 21:47
roossienb pushed a commit to roossienb/GeneralsGameCode that referenced this pull request Mar 29, 2025
roossienb pushed a commit to roossienb/GeneralsGameCode that referenced this pull request Mar 29, 2025
roossienb pushed a commit to roossienb/GeneralsGameCode that referenced this pull request Mar 29, 2025
@roossienb roossienb force-pushed the fix/zh/warnings-level-1 branch from add6c02 to 5e4ede3 Compare March 29, 2025 22:00
roossienb pushed a commit to roossienb/GeneralsGameCode that referenced this pull request Mar 29, 2025
roossienb pushed a commit to roossienb/GeneralsGameCode that referenced this pull request Mar 29, 2025
roossienb pushed a commit to roossienb/GeneralsGameCode that referenced this pull request Mar 29, 2025
roossienb pushed a commit to roossienb/GeneralsGameCode that referenced this pull request Mar 29, 2025
roossienb pushed a commit to roossienb/GeneralsGameCode that referenced this pull request Mar 29, 2025
roossienb pushed a commit to roossienb/GeneralsGameCode that referenced this pull request Mar 29, 2025
@roossienb roossienb force-pushed the fix/zh/warnings-level-1 branch from 5e4ede3 to 5da039b Compare March 29, 2025 22:03
@roossienb

This comment was marked as outdated.

roossienb pushed a commit to roossienb/GeneralsGameCode that referenced this pull request Mar 29, 2025
roossienb pushed a commit to roossienb/GeneralsGameCode that referenced this pull request Mar 29, 2025
roossienb pushed a commit to roossienb/GeneralsGameCode that referenced this pull request Mar 29, 2025
@roossienb roossienb force-pushed the fix/zh/warnings-level-1 branch from 6cc3b43 to d21a323 Compare April 2, 2025 07:04
roossienb pushed a commit to roossienb/GeneralsGameCode that referenced this pull request Apr 2, 2025
Copy link

@xezon xezon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a bit skeptical about integer to float changes. What if it changes a math operation somewhere unexpectedly? According to a chatgpt inquiry it could change floating point precision in regards to optimizing more complex statements.

Maybe it would be better to

  • Disable warning C5055 in cmake and revert all changes that addressed it

or

@helmutbuhler
Copy link

I am a bit skeptical about integer to float changes. What if it changes a math operation somewhere unexpectedly? According to a chatgpt inquiry it could change floating point precision in regards to optimizing more complex statements.

Maybe it would be better to

* Disable warning C5055 in cmake and revert all changes that addressed it

or

* Test that integer to float conversions introduce no game state changes. This would require feature implementation [Implement feature to verify replay playback correctness #566](https://github.com/TheSuperHackers/GeneralsGameCode/issues/566)

Regarding replay checking: I will probably need some time to implement this, but you can already check this manually:

  • Merge: [ZH] Fix Replay CRC Checking #545
  • Create a replay in the retail version or get an existing one
  • Load the replay in the VC6 release build with the PR above merge and check that no mismatch message appears during playback.

But I also agree, one tiny mistake and we introduce a possible mismatch that might be hard to find. Also these types of warnings rarely indicate real flaws in my experience. So just supressing that warning doesn't seem like such a bad idea to me.

@roossienb
Copy link
Author

roossienb commented Apr 3, 2025

@xezon, @Mauller, @helmutbuhler There seems to be some concern about floats and after careful consideration, I have to agree with those. Therefore, my proposal is to pick the following.

  • signed/unsigned conversion (Trig and random - we have discussed this on discord)
  • casting to HRESULT
  • Fixing string formatting
  • Use unsigned int in for-loops rather than signed int.
  • Fix compiler warnings for uninitialised variables in copy constructors

and discard the others. This still resolves about 2000 warnings.
The branch consists of multiple commits, so I can easily cherry-pick.

roossienb pushed a commit to roossienb/GeneralsGameCode that referenced this pull request Apr 3, 2025
roossienb pushed a commit to roossienb/GeneralsGameCode that referenced this pull request Apr 3, 2025
roossienb pushed a commit to roossienb/GeneralsGameCode that referenced this pull request Apr 3, 2025
roossienb pushed a commit to roossienb/GeneralsGameCode that referenced this pull request Apr 3, 2025
roossienb pushed a commit to roossienb/GeneralsGameCode that referenced this pull request Apr 3, 2025
roossienb pushed a commit to roossienb/GeneralsGameCode that referenced this pull request Apr 3, 2025
roossienb pushed a commit to roossienb/GeneralsGameCode that referenced this pull request Apr 3, 2025
@roossienb roossienb force-pushed the fix/zh/warnings-level-1 branch from bbf389e to 4a9e82b Compare April 3, 2025 19:02
roossienb pushed a commit to roossienb/GeneralsGameCode that referenced this pull request Apr 3, 2025
roossienb pushed a commit to roossienb/GeneralsGameCode that referenced this pull request Apr 3, 2025
@roossienb
Copy link
Author

I've undone the float castings.

@roossienb roossienb force-pushed the fix/zh/warnings-level-1 branch from dda2218 to 037483a Compare April 7, 2025 13:27
Copy link

@Mauller Mauller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to go for me, if we get a quick VC6 check with the golden sample replay then it should help identify that the Trig removal is fine and the retail game does not use it either.

@roossienb
Copy link
Author

VC6 replay tested and verified

@xezon xezon changed the title [ZH] Fixes Level 1 warnings for Zero hour [ZH] Fix level 1 compiler warnings for implicit integer type conversions and uninitialized variables in copy constructors Apr 9, 2025
static_cast<int>(0x7439a9d4), static_cast<int>(0x9cea8ac5), static_cast<int>(0x89537c5c), static_cast<int>(0x2588f55d),
static_cast<int>(0x415b5e1d), static_cast<int>(0x216e3d95), static_cast<int>(0x85c662e7), static_cast<int>(0x5e8ab368),
static_cast<int>(0x3ea5cc8c), static_cast<int>(0xd26a0f74), static_cast<int>(0xf3a9222b), static_cast<int>(0x48aad7e4)
(int)0xbaa96887, (int)0x1e17d32c, (int)0x03bcdc3c, (int)0x0f33d1b2,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second commit should be merged into the first commit, because they touch the exact same code.

0x07439a9d4, 0x09cea8ac5, 0x089537c5c, 0x02588f55d,
0x0415b5e1d, 0x0216e3d95, 0x085c662e7, 0x05e8ab368,
0x03ea5cc8c, 0x0d26a0f74, 0x0f3a9222b, 0x048aad7e4
static_cast<int>(0xbaa96887), static_cast<int>(0x1e17d32c), static_cast<int>(0x03bcdc3c), static_cast<int>(0x0f33d1b2),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first commit uses different wording style than the other commits.

It should say

"[ZH] Fix compiler warnings for [...]"

@@ -531,9 +531,13 @@ class GlobalData : public SubsystemInterface
GlobalData *newOverride( void ); /** create a new override, copy data from previous
override, and return it */


#if defined(_MSC_VER) && _MSC_VER < 1300
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"uninitialised" is misspelled in third commit title.

@xezon
Copy link

xezon commented Apr 9, 2025

Perhaps replicate the fixes straight into Generals as well and have 2 commits for [GEN][ZH] ? Would be clean. You could also open 2 Pull Requests for each of the commits, because this pull request has already undergone massive transformation.

roossienb pushed a commit to roossienb/GeneralsGameCode that referenced this pull request Apr 9, 2025
… to signed integer

[GEN] Changing cast to c-type (TheSuperHackers#549)

[ZH] Fixed warnings of implicit conversion from unsigned to signed integer (TheSuperHackers#534)

[ZH] Changing cast to c-type (TheSuperHackers#534)
@roossienb
Copy link
Author

Closing this in favour of two new PR's as discussed above

#639
#640

@roossienb roossienb closed this Apr 9, 2025
@roossienb roossienb deleted the fix/zh/warnings-level-1 branch April 10, 2025 06:29
roossienb pushed a commit to roossienb/GeneralsGameCode that referenced this pull request May 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Build Anything related to building, compiling ZeroHour Relates to Zero Hour
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix Compiler Warnings - Zero Hour + Tools - Level 1 warnings
6 participants