-
Notifications
You must be signed in to change notification settings - Fork 66
[ZH] Fix loop index comparison warnings #804
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
base: main
Are you sure you want to change the base?
Conversation
14f7171
to
8aa4016
Compare
If you are going to change int to an unsigned type then I think std::size_t would be more appropriate and in line with standard conventions. Where range loops can be used then they should be preferred |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fairly safe, but I suggest to give it a test for mismatch, especially with a focus on USA Countermeasures.
size_t
is identical to std::size_t
.
@@ -413,7 +413,7 @@ static void findHighFileNumber( AsciiString filename, void *userData ) | |||
|
|||
// strip off the extension at the end of the filename | |||
AsciiString nameOnly = filename; | |||
for( Int count = 0; count < strlen( SAVE_GAME_EXTENSION ); count++ ) | |||
for( size_t count = 0; count < strlen( SAVE_GAME_EXTENSION ); count++ ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this will call strlen on every iteration...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah i think the VC6 version may do that but modern MSVC would likely compile it out as a constant.
@@ -579,7 +579,7 @@ Bool MapCache::loadUserMaps() | |||
{ | |||
AsciiString endingStr; | |||
AsciiString fname = s+1; | |||
for (Int i=0; i<strlen(mapExtension); ++i) | |||
for (size_t i=0; i<strlen(mapExtension); ++i) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another strlen in condition...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah... i didn't want to change too much.
@@ -301,7 +301,7 @@ void CountermeasuresBehavior::launchVolley() | |||
Object *obj = getObject(); | |||
|
|||
Real volleySize = (Real)data->m_volleySize; | |||
for( int i = 0; i < data->m_volleySize; i++ ) | |||
for( UnsignedInt i = 0; i < data->m_volleySize; i++ ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope this will produce the same float value below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In theory it should as the raw binary values of positive signed int and unsigned int values are the same up to 2.7 billion at least.
8aa4016
to
f4c5b85
Compare
Updated this with the inclusion of a cast that was missing in one of the loops. |
f4c5b85
to
c0eff59
Compare
Just rebased off recent main after the other warning fixes were merged. |
Just ran Golden Replay 1 against this with the VC6 build and it did not mismatch. So I think the changes are fairly safe, i can replicate the changes to generals if people are happy. |
This PR fixes loop index comparison warnings by matching the data type of the loop index to match the comparison values data type.
TODO: