Skip to content
Permalink
Browse files
Fix inconsistent integer comparison warnings
  • Loading branch information
SmallJoker committed Aug 17, 2021
1 parent 2eec997 commit 3b842a7e021f61c119f060df5de035b71df1fe83
Showing with 5 additions and 5 deletions.
  1. +1 −1 src/client/imagefilters.cpp
  2. +4 −4 src/settings.cpp
@@ -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++) {
@@ -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])
@@ -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)

0 comments on commit 3b842a7

Please sign in to comment.