Skip to content

Commit

Permalink
Fix inconsistent integer comparison warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
SmallJoker committed Aug 17, 2021
1 parent 2eec997 commit 3b842a7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/client/imagefilters.cpp
Expand Up @@ -102,7 +102,7 @@ void imageCleanTransparent(video::IImage *src, u32 threshold)

// Then repeatedly look for transparent pixels, filling them in until
// we're finished.
for (u32 iter = 0; iter < iter_max; iter++) {
for (int iter = 0; iter < iter_max; iter++) {

for (u32 ctry = 0; ctry < dim.Height; ctry++)
for (u32 ctrx = 0; ctrx < dim.Width; ctrx++) {
Expand Down
8 changes: 4 additions & 4 deletions src/settings.cpp
Expand Up @@ -49,15 +49,15 @@ SettingsHierarchy::SettingsHierarchy(Settings *fallback)

Settings *SettingsHierarchy::getLayer(int layer) const

This comment has been minimized.

Copy link
@randomMesh

randomMesh Aug 17, 2021

I would make the parameter 'layer' an unsigned int rather than casting the result of vector::size.
'layer' is used as an index which can't be negative.

This 'fix' makes it worse.

This comment has been minimized.

Copy link
@SmallJoker

SmallJoker Aug 17, 2021

Author Member

Settings which are not part of any hierarchy, for example in unittests or mod.conf have a value of -1 to indicate that.
Since the introduction of the m_hierarchy member this special case might be no longer needed, but two safety checks are at least better than one.

This comment has been minimized.

Copy link
@randomMesh

randomMesh Aug 17, 2021

Ok ,didn't think of the unit tests. Sorry for the noise.

{
if (layer < 0 || layer >= layers.size())
if (layer < 0 || layer >= (int)layers.size())
throw BaseException("Invalid settings layer");
return layers[layer];
}


Settings *SettingsHierarchy::getParent(int layer) const
{
assert(layer >= 0 && layer < layers.size());
assert(layer >= 0 && layer < (int)layers.size());
// iterate towards the origin (0) to find the next fallback layer
for (int i = layer - 1; i >= 0; --i) {
if (layers[i])
Expand All @@ -72,8 +72,8 @@ void SettingsHierarchy::onLayerCreated(int layer, Settings *obj)
{
if (layer < 0)
throw BaseException("Invalid settings layer");
if (layers.size() < layer+1)
layers.resize(layer+1);
if ((int)layers.size() < layer + 1)
layers.resize(layer + 1);

Settings *&pos = layers[layer];
if (pos)
Expand Down

0 comments on commit 3b842a7

Please sign in to comment.