diff --git a/src/server.cpp b/src/server.cpp index 1325bdd027..22c991f666 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1382,7 +1382,8 @@ void CServer::SendChatTextToAllConChannels ( const int iSendingChanID, const QSt bool CServer::SendChatTextToConChannel ( const int iCurChanID, const QString& strChatText ) { - if ( !MathUtils::InRange ( iCurChanID, 0, iMaxNumChannels - 1 ) || !vecChannels[iCurChanID].IsConnected() ) + // Check if iCurChanID is in range [0, iMaxNumChannels) + if ( !MathUtils::InRange ( iCurChanID, 0, iMaxNumChannels ) || !vecChannels[iCurChanID].IsConnected() ) { return false; } diff --git a/src/util.h b/src/util.h index 1185c56936..f7f5afe189 100644 --- a/src/util.h +++ b/src/util.h @@ -1243,11 +1243,11 @@ class MathUtils } } - // return true if a value is within the lower and upper bounds (inclusively), otherwise false + // Returns true if value is in [lower, upper) (inclusive lower, exclusive upper). template - static inline bool InRange ( T value, T lower, T upper ) + static inline bool InRange ( T value, T lower /* inclusive */, T upper /* exclusive */ ) { - return !( value < lower || value > upper ); + return value >= lower && value < upper; } };